Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Deribit Rust Client
Type-safe, async Rust client for the Deribit WebSocket JSON‑RPC v2 API. Request/response types are generated at build time from the official API spec, and a single connection supports both RPC calls and streaming subscriptions.
✨ Features
- 🏗️ Build-time codegen from Deribit’s spec (production by default, optional Testnet)
- ⚡ Async WebSocket JSON‑RPC 2.0 over a single multiplexed connection
- 🦀 Strongly-typed requests, responses, and enums
- 📡 Simple subscriptions API for public and private channels
- 🔁 Concurrency-friendly: methods take
&self(nomut), and the client is shareable viaArc
🚀 Quick Start
Add the crate and tokio to your Cargo.toml:
[]
= "0.1.0"
= { = "1", = ["rt-multi-thread", "macros"] }
= "0.3" # for StreamExt in subscription examples
▶️ Basic usage
Public call example: fetch server time.
use ;
async
🔐 Authentication + private methods
Authenticate using client credentials and fetch an account summary.
use ;
async
📡 Streaming subscriptions
Untyped variant: subscribe by channel string and receive a Stream of serde_json::Value.
use ;
use StreamExt;
async
Typed variant: use generated channel types and get a Stream of typed messages.
use ;
use StreamExt;
async
🧪 Testnet
- Connect with
Env::Testnet:
let client = connect.await?;
- Enable the feature to also generate Testnet types:
When the testnet feature is enabled, production types live at the crate root (deribit_api::*), and Testnet‑generated types are available under deribit_api::testnet::*.
🧩 API model
- Each endpoint like
public/get_timemaps to a request struct namedPublicGetTimeRequest. - Send requests via
client.call(request).await. - Responses deserialize into generated structs/enums where possible, or
serde_json::Valuefor generic schemas. - Subscriptions expose generated channel structs (e.g.,
TradesInstrumentNameChannel) implementing theSubscriptiontrait. Useclient.subscribe(channel).await?for typed streams, orclient.subscribe_raw("...")for untyped.
Error type: all calls return Result<T, deribit_api::Error> (covers RPC, WebSocket, and JSON decode errors).
🧵 Low-level: call_raw
If you want to call a method by name with ad‑hoc JSON parameters, use call_raw. It returns a serde_json::Value.
Requires adding serde_json to your Cargo.toml:
[]
= "1"
use ;
use json;
async
🤝 Concurrency and sharing
The client is safe to share across tasks using std::sync::Arc and does not require mut. All methods take &self and internally multiplex over a single WebSocket connection.
use Arc;
use ;
use StreamExt;
async
🔧 Configuration
Override the API spec URL (or point to a local file) through package metadata. The build script will use it for codegen.
[]
= "./deribit_api_v2.json" # or an https:// URL
📚 Examples
This repo ships several runnable examples:
# Public calls
# Subscriptions
# Authentication + private endpoints
# Testnet (enables the feature and uses the Testnet endpoint)
# Low-level + untyped stream
# Concurrent RPC + subscription on one connection
🛠️ Development
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
⚠️ Disclaimer
This software is for educational and development purposes. Use at your own risk when trading with real funds.