#trading #api-client #api-bindings #subscription #communication #websocket #ws

deribit

Rust 版 Deribit 客户端。请参阅测试/示例以获取详细用法。

15 个版本

0.3.3 2023 年 4 月 2 日
0.3.2 2021 年 4 月 17 日
0.3.0 2020 年 8 月 10 日
0.2.1 2020 年 7 月 22 日
0.1.2 2019 年 4 月 28 日

#2 in #ws

Download history 22/week @ 2024-07-01 73/week @ 2024-07-29

每月下载量73

MIT 许可证

120KB
3.5K SLoC

Rust 语言 Deribit API V2 客户端

CI Latest Version Rustc Version nightly license keybase logo btc

请自行承担使用此库进行交易的风险。

当前计划是仅实现 WebSocket 通信,包括通过 WebSocket 调用 API 和 WebSocket 订阅。我将首先实现这些用于我自己的交易目的的 API,但如果您希望某些 API 优先实现,请提交一个问题或直接提交 PR(这更受欢迎: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);
}

实现状态

  • 身份验证
    • /public/auth
    • /public/exchange_token
    • /public/fork_token
    • /private/logout
  • 会话管理
    • /public/set_heartbeat
    • /public/disable_heartbeat
    • /private/enable_cancel_on_disconnect
    • /private/disable_cancel_on_disconnect
    • /private/get_cancel_on_disconnect
  • 支持
    • /public/get_time
    • /public/hello
    • /public/test
  • 订阅管理
    • /public/subscribe
    • /public/unsubscribe
    • /private/subscribe
    • /private/unsubscribe
  • 账户管理
    • /public/get_announcements
    • /private/change_api_key_name
    • /private/change_scope_in_api_key
    • /private/change_subaccount_name
    • /private/create_api_key
    • /private/create_subaccount
    • /private/disable_api_key
    • /private/disable_tfa_for_subaccount
    • /private/enable_api_key
    • /private/get_account_summary
    • /private/get_email_language
    • /private/get_new_announcements
    • /private/get_position
    • /private/get_positions
    • /private/get_subaccounts
    • /private/list_api_keys
    • /private/remove_api_key
    • /private/reset_api_key
    • /private/set_announcement_as_read
    • /private/set_api_key_as_default
    • /private/set_email_for_subaccount
    • /private/set_email_language
    • /private/set_password_for_subaccount
    • /private/toggle_notifications_from_subaccount
    • /private/toggle_subaccount_login
  • 批量交易
    • /private/execute_block_trade
    • /private/get_block_trade
    • /private/get_last_block_trades_by_currency
    • /private/invalidate_block_trade_signature
    • /private/verify_block_trade
  • 交易
    • /private/buy
    • /private/sell
    • /private/edit
    • /private/cancel
    • /private/cancel_all
    • /private/cancel_all_by_currency
    • /private/cancel_all_by_instrument
    • /private/cancel_by_label
    • /private/close_position
    • /private/get_margins
    • /private/get_open_orders_by_currency
    • /private/get_open_orders_by_instrument
    • /private/get_order_history_by_currency
    • /private/get_order_history_by_instrument
    • /private/get_order_margin_by_ids
    • /private/get_order_state
    • /private/get_stop_order_history
    • /private/get_user_trades_by_currency
    • /private/get_user_trades_by_currency_and_time
    • /private/get_user_trades_by_instrument
    • /private/get_user_trades_by_instrument_and_time
    • /private/get_user_trades_by_order
    • /private/get_settlement_history_by_instrument
    • /private/get_settlement_history_by_currency
  • 市场数据
    • /public/get_book_summary_by_currency
    • /public/get_book_summary_by_instrument
    • /public/get_contract_size
    • /public/get_currencies
    • /public/get_funding_chart_data
    • /public/get_funding_rate_history
    • /public/get_funding_rate_value
    • /public/get_historical_volatility
    • /public/get_index
    • /public/get_instruments
    • /public/get_last_settlements_by_currency
    • /public/get_last_settlements_by_instrument
    • /public/get_last_trades_by_currency
    • /public/get_last_trades_by_currency_and_time
    • /public/get_last_trades_by_instrument
    • /public/get_last_trades_by_instrument_and_time
    • /public/get_order_book
    • /public/get_trade_volumes
    • /public/get_tradingview_chart_data
    • /public/ticker
  • 钱包
    • /private/cancel_transfer_by_id
    • /private/cancel_withdrawal
    • /private/create_deposit_address
    • /private/get_current_deposit_address
    • /private/get_deposits
    • /private/get_transfers
    • /private/get_withdrawals
    • /private/submit_transfer_to_subaccount
    • /private/submit_transfer_to_user
    • /private/withdraw
  • 订阅
    • 公告
    • book.{instrument_name}.{group}.{depth}.{interval}
    • book.{instrument_name}.{interval}
    • chart.trades.{instrument_name}.{resolution}
    • deribit_price_index.{index_name}
    • deribit_price_ranking.{index_name}
    • estimated_expiration_price.{index_name}
    • markprice.options.{index_name}
    • perpetual.{instrument_name}.{interval}
    • platform_state
    • quote.{instrument_name}
    • ticker.{instrument_name}.{interval}
    • trades.{instrument_name}.{interval}
    • trades.{kind}.{currency}.{interval}
    • user.changes.{instrument_name}.{interval}
    • user.changes.{kind}.{currency}.{interval}
    • user.orders.{instrument_name}.{interval}
    • user.orders.{kind}.{currency}.{interval}
    • user.portfolio.{currency}
    • user.trades.{instrument_name}.{interval}
    • user.trades.{kind}.{currency}.{interval}

捐赠

donationqr

16PeVqncfWoQ94M4pxnitkYnnW8agQBBZB

依赖项

~10–21MB
~306K SLoC