| Crates.io | deribit-http |
| lib.rs | deribit-http |
| version | 0.4.0 |
| created_at | 2025-07-21 17:20:03.566318+00 |
| updated_at | 2025-09-22 13:21:05.993569+00 |
| description | HTTP REST API client for Deribit trading platform |
| homepage | https://github.com/joaquinbejar/deribit-http |
| repository | https://github.com/joaquinbejar/deribit-http |
| max_upload_size | |
| id | 1762282 |
| size | 1,012,355 |
Asynchronous HTTP client for the Deribit API, designed for server integrations,
batch jobs and tooling that prefer REST/HTTP over WebSocket. Built on top of
reqwest and tokio, it provides a typed set of methods for public and
private endpoints, OAuth2 authentication, category-based rate limiting and
Serde-powered data models.
This crate-level documentation is intended to be used by cargo readme to generate the README.
DeribitHttpClient::new() or default.exchange_token and fork_token.ApiResponse/ApiError.use deribit_http::DeribitHttpClient;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// true = testnet, false = mainnet
let client = DeribitHttpClient::new();
// Public calls (no authentication required)
let currencies = client.get_currencies().await?;
println!("Supports {} currencies", currencies.len());
// Example: ticker
let ticker = client.get_ticker("BTC-PERPETUAL").await?;
println!("Mark price: {}", ticker.mark_price);
Ok(())
}
DeribitHttpClient::authenticate_oauth2(client_id, client_secret) returns an AuthToken and keeps it in the AuthManager.is_authenticated(), get_auth_token().exchange_token(refresh_token, subject_id, scope) and fork_token(refresh_token, session_name, scope).authenticate_api_key method exists but is currently not implemented and will return an error.DeribitHttpClient::new() for Testnet and new(false) for Production.DeribitHttpClient::with_config(HttpConfig) lets you set base_url, timeout, user_agent, testnet, and optional credentials.auth: AuthManager (OAuth2, token management) and related types (e.g. AuthRequest).client: DeribitHttpClient, public/private methods, auth helpers, exchange_token and fork_token.config: HttpConfig and environment helpers (testnet/production) and headers/base_url.connection and session: infrastructure support types (shared across the ecosystem).endpoints: HTTP implementation of public and private methods (see coverage below).error: HttpError variants such as NetworkError, RequestFailed, InvalidResponse, AuthenticationFailed, ConfigError.message and model: HTTP types (ApiResponse, ApiError, AuthToken, etc.).rate_limit: RateLimiter and categorize_endpoint with per-category limits.constants: base URLs (production/testnet), endpoint routes, and common headers.The following methods exist on DeribitHttpClient within endpoints::public:
get_currencies().get_index(currency), get_index_price(index_name), get_index_price_names().get_book_summary_by_currency(currency, kind), get_book_summary_by_instrument(instrument_name).get_instrument(instrument_name), get_instruments(currency, kind, expired), get_contract_size(instrument_name).get_server_time(), test_connection(), get_status().get_ticker(instrument_name), get_order_book(instrument_name, depth), get_order_book_by_instrument_id(instrument_id, depth).get_last_trades(instrument_name, ...), get_last_trades_by_currency(...),
get_last_trades_by_currency_and_time(...), get_last_trades_by_instrument_and_time(...).get_historical_volatility(currency), get_apr_history(currency, ...).get_funding_chart_data(instrument_name, length), get_funding_rate_history(instrument_name, start, end), get_funding_rate_value(instrument_name, start, end).get_tradingview_chart_data(instrument_name, start, end, resolution).get_delivery_prices(index_name, ...), get_expirations(currency, kind, currency_pair).hello(client_name, client_version) is documented but WebSocket-only; in HTTP it will return a configuration error.Included models (re-exported): Currency, IndexData, BookSummary, Instrument, Trade,
TickerData, OrderBook, FundingChartData, TradingViewChartData, DeliveryPricesResponse,
ExpirationsResponse, FundingRateData, SettlementsResponse, LastTradesResponse, etc.
Require valid authentication (OAuth2). Examples include:
get_subaccounts(), get_transaction_log(...), get_deposits(...), get_withdrawals(...).buy_order(...), sell_order(...), cancel_order(order_id).get_account_summary(currency, ...).Useful re-exported models: Subaccount, TransactionLog, DepositsResponse, WithdrawalsResponse,
OrderResponse, OrderInfo, AccountSummary, Position, PortfolioInfo, etc.
/public/hello and /private/logout) and are not available in this HTTP client.authenticate_api_key stub exists but is not yet implemented in the HTTP client.ApiResponse<T> in a strongly-typed manner.The HttpError type centralizes common failures: network issues (NetworkError),
non-success HTTP responses (RequestFailed), parsing/structure errors (InvalidResponse),
authentication failures (AuthenticationFailed), and configuration conditions (ConfigError).
The RateLimiter categorizes each URL and applies a token-bucket scheme per category
(Trading, MarketData, Account, Auth, General). You can inspect it via rate_limiter().
This crate-level header is consumed by cargo readme. To generate the README:
cargo readme -o README.md
Ensure you have cargo-readme installed (cargo install cargo-readme).
We welcome contributions to this project! If you would like to contribute, please follow these steps:
If you have any questions, issues, or would like to provide feedback, please feel free to contact the project maintainer:
We appreciate your interest and look forward to your contributions!
Licensed under MIT license
This software is not officially associated with Deribit. Trading financial instruments carries risk, and this library is provided as-is without any guarantees. Always test thoroughly with a demo account before using in a live trading environment.