Crates.io | deribit |
lib.rs | deribit |
version | 0.3.3 |
source | src |
created_at | 2019-04-25 07:07:51.90893 |
updated_at | 2023-04-02 00:37:36.028918 |
description | Rust client for deribit. Please look at tests/examples for detailed usages. |
homepage | |
repository | https://github.com/dovahcrow/deribit-rs |
max_upload_size | |
id | 130081 |
size | 194,703 |
Use this library for trading at your own risk.
The current plan is to only implement the websocket communication, which includes call api through websocket and websocket subscription. I will first implement these APIs used for my own trading purpose, however, if you want some APIs to be prioritly implemented please open an issue or just throw me a PR (this is more welcome :P).
// This will give you a Deribit instance, which the only purpose is to create connection.
let drb = deribit::DeribitBuilder::default().build().expect("Cannot create deribit client");
// "Deribit::connect" will connect to the deribit server with websocket as well as
// spin up a task in the backgroud polling message and dispatch them to subscription channel or RPC channel respectively.
// "Deribit::connect" returns a "(DeribitAPIClient, DeribitSubscriptionClient)" tuple, where
// the former is used for sending out RPC requests, and the later is used for receiving notifications.
let (mut client, mut subscription) = drb.connect().await?;
// All the request models reside in "deribit::models" module, with the
// naming convention of "camelCase(method)+Request", e.g. "/public/test" would be
// "TestRequest" in deribit-rs.
let req = deribit::models::TestRequest::default();
// Calls to deribit server is made by giving "DeribitAPIClient::call" the request object.
// The return type of "DeribitAPIClient::call" is "impl Future<Output=impl Future<Output=R>>",
// where the first layer future denotes the send process, and the second one denotes the receive process. This brings
// fine grained control of the communication. The response type "R" depends on your request, with similar naming convention:
// "TestRequest" will have "TestResponse".
let _ = client.call(req).await?.await?;
// Subscription is made by calling with "PublicSubscribeRequest" or "PrivateSubscribeRequest".
let req = PublicSubscribeRequest::new(&["book.BTC-PERPETUAL.raw".into()]);
// You can avoid the second ".await" to save some time - no worries, the request will still be received by the deribit server.
let _ = client.call(req).await?;
// In order to get your subscriptions, just poll the subscription stream. The "DeribitSubscriptionClient" implements the "futures::Stream" trait.
while let Some(message) = subscription.next().await {
println!("Subscription message received {:?}", message);
}
16PeVqncfWoQ94M4pxnitkYnnW8agQBBZB