pub struct DeribitHttpClient { /* private fields */ }Expand description
HTTP client for Deribit REST API
Implementations§
Source§impl DeribitHttpClient
impl DeribitHttpClient
Sourcepub fn with_config(config: HttpConfig) -> Self
pub fn with_config(config: HttpConfig) -> Self
Create a new HTTP client with custom configuration
Sourcepub fn config(&self) -> &HttpConfig
pub fn config(&self) -> &HttpConfig
Get the configuration
Sourcepub fn http_client(&self) -> &Client
pub fn http_client(&self) -> &Client
Get the HTTP client
Sourcepub async fn make_request(&self, url: &str) -> Result<Response, HttpError>
pub async fn make_request(&self, url: &str) -> Result<Response, HttpError>
Make a rate-limited HTTP request
Sourcepub async fn make_authenticated_request(
&self,
url: &str,
) -> Result<Response, HttpError>
pub async fn make_authenticated_request( &self, url: &str, ) -> Result<Response, HttpError>
Make an authenticated HTTP GET request for private endpoints
Sourcepub async fn make_authenticated_post_request<T: Serialize>(
&self,
url: &str,
body: &T,
) -> Result<Response, HttpError>
pub async fn make_authenticated_post_request<T: Serialize>( &self, url: &str, body: &T, ) -> Result<Response, HttpError>
Make an authenticated HTTP POST request for private endpoints
Sourcepub fn rate_limiter(&self) -> &RateLimiter
pub fn rate_limiter(&self) -> &RateLimiter
Get rate limiter for advanced usage
Source§impl DeribitHttpClient
Private endpoints implementation
impl DeribitHttpClient
Private endpoints implementation
Sourcepub async fn get_subaccounts(
&self,
with_portfolio: Option<bool>,
) -> Result<Vec<Subaccount>, HttpError>
pub async fn get_subaccounts( &self, with_portfolio: Option<bool>, ) -> Result<Vec<Subaccount>, HttpError>
Get subaccounts
Retrieves the list of subaccounts associated with the main account.
§Arguments
with_portfolio- Include portfolio information (optional)
§Examples
use deribit_http::DeribitHttpClient;
let client = DeribitHttpClient::new();
// let subaccounts = client.get_subaccounts(Some(true)).await?;
// tracing::info!("Found {} subaccounts", subaccounts.len());Sourcepub async fn get_transaction_log(
&self,
request: TransactionLogRequest,
) -> Result<TransactionLogResponse, HttpError>
pub async fn get_transaction_log( &self, request: TransactionLogRequest, ) -> Result<TransactionLogResponse, HttpError>
Get transaction log
Retrieves transaction log entries for the account.
§Arguments
request- ATransactionLogRequeststruct containing:currency- Currency symbol (BTC, ETH, etc.)start_timestamp- Start timestamp in milliseconds (optional)end_timestamp- End timestamp in milliseconds (optional)count- Number of requested items (optional, default 10)continuation- Continuation token for pagination (optional)
§Examples
use deribit_http::DeribitHttpClient;
use crate::model::TransactionLogRequest;
let client = DeribitHttpClient::new();
// let request = TransactionLogRequest { currency: "BTC".into(), ..Default::default() };
// let log = client.get_transaction_log(request).await?;Sourcepub async fn get_deposits(
&self,
currency: &str,
count: Option<u32>,
offset: Option<u32>,
) -> Result<DepositsResponse, HttpError>
pub async fn get_deposits( &self, currency: &str, count: Option<u32>, offset: Option<u32>, ) -> Result<DepositsResponse, HttpError>
Get deposits
Retrieves the latest user deposits.
§Arguments
currency- Currency symbol (BTC, ETH, etc.)count- Number of requested items (optional, default 10)offset- Offset for pagination (optional, default 0)
§Examples
use deribit_http::DeribitHttpClient;
let client = DeribitHttpClient::new();
// let deposits = client.get_deposits("BTC", Some(20), Some(0)).await?;
// tracing::info!("Found {} deposits", deposits.data.len());Sourcepub async fn get_withdrawals(
&self,
currency: &str,
count: Option<u32>,
offset: Option<u32>,
) -> Result<WithdrawalsResponse, HttpError>
pub async fn get_withdrawals( &self, currency: &str, count: Option<u32>, offset: Option<u32>, ) -> Result<WithdrawalsResponse, HttpError>
Get withdrawals
Retrieves the latest user withdrawals.
§Arguments
currency- Currency symbol (BTC, ETH, etc.)count- Number of requested items (optional, default 10)offset- Offset for pagination (optional, default 0)
§Examples
use deribit_http::DeribitHttpClient;
let client = DeribitHttpClient::new();
// let withdrawals = client.get_withdrawals("BTC", Some(20), Some(0)).await?;
// tracing::info!("Found {} withdrawals", withdrawals.data.len());Sourcepub async fn submit_transfer_to_subaccount(
&self,
currency: &str,
amount: f64,
destination: u64,
) -> Result<TransferResultResponse, HttpError>
pub async fn submit_transfer_to_subaccount( &self, currency: &str, amount: f64, destination: u64, ) -> Result<TransferResultResponse, HttpError>
Submit transfer to subaccount
Transfers funds to a subaccount.
§Arguments
currency- Currency symbol (BTC, ETH, etc.)amount- Amount of funds to be transferreddestination- ID of destination subaccount
§Examples
use deribit_http::DeribitHttpClient;
let client = DeribitHttpClient::new();
// let transfer = client.submit_transfer_to_subaccount("BTC", 0.001, 123).await?;
// tracing::info!("Transfer ID: {}", transfer.id);Sourcepub async fn submit_transfer_to_user(
&self,
currency: &str,
amount: f64,
destination: &str,
) -> Result<TransferResultResponse, HttpError>
pub async fn submit_transfer_to_user( &self, currency: &str, amount: f64, destination: &str, ) -> Result<TransferResultResponse, HttpError>
Submit transfer to user
Transfers funds to another user.
§Arguments
currency- Currency symbol (BTC, ETH, etc.)amount- Amount of funds to be transferreddestination- Destination wallet address from address book
§Examples
use deribit_http::DeribitHttpClient;
let client = DeribitHttpClient::new();
// let transfer = client.submit_transfer_to_user("ETH", 0.1, "0x1234...").await?;
// tracing::info!("Transfer ID: {}", transfer.id);Sourcepub async fn buy_order(
&self,
request: OrderRequest,
) -> Result<OrderResponse, HttpError>
pub async fn buy_order( &self, request: OrderRequest, ) -> Result<OrderResponse, HttpError>
Place a buy order
Places a buy order for the specified instrument.
§Arguments
request- The buy order request parameters
Sourcepub async fn sell_order(
&self,
request: OrderRequest,
) -> Result<OrderResponse, HttpError>
pub async fn sell_order( &self, request: OrderRequest, ) -> Result<OrderResponse, HttpError>
Place a sell order
Places a sell order for the specified instrument.
§Arguments
request- The sell order request parameters
Sourcepub async fn cancel_order(
&self,
order_id: &str,
) -> Result<OrderInfoResponse, HttpError>
pub async fn cancel_order( &self, order_id: &str, ) -> Result<OrderInfoResponse, HttpError>
Sourcepub async fn cancel_all(&self) -> Result<u32, HttpError>
pub async fn cancel_all(&self) -> Result<u32, HttpError>
Cancel all orders
Cancels all orders for the account.
§Returns
Returns the number of cancelled orders.
Sourcepub async fn cancel_all_by_currency_pair(
&self,
currency_pair: &str,
) -> Result<u32, HttpError>
pub async fn cancel_all_by_currency_pair( &self, currency_pair: &str, ) -> Result<u32, HttpError>
Sourcepub async fn cancel_all_by_instrument(
&self,
instrument_name: &str,
) -> Result<u32, HttpError>
pub async fn cancel_all_by_instrument( &self, instrument_name: &str, ) -> Result<u32, HttpError>
Sourcepub async fn cancel_all_by_kind_or_type(
&self,
kind: Option<&str>,
order_type: Option<&str>,
) -> Result<u32, HttpError>
pub async fn cancel_all_by_kind_or_type( &self, kind: Option<&str>, order_type: Option<&str>, ) -> Result<u32, HttpError>
Sourcepub async fn get_account_summary(
&self,
currency: &str,
extended: Option<bool>,
) -> Result<AccountSummaryResponse, HttpError>
pub async fn get_account_summary( &self, currency: &str, extended: Option<bool>, ) -> Result<AccountSummaryResponse, HttpError>
Get account summary
Retrieves account summary information including balance, margin, and other account details.
§Arguments
currency- Currency to get summary for (BTC, ETH, USDC, etc.)extended- Whether to include extended information
Sourcepub async fn get_positions(
&self,
currency: Option<&str>,
kind: Option<&str>,
subaccount_id: Option<i32>,
) -> Result<Vec<Position>, HttpError>
pub async fn get_positions( &self, currency: Option<&str>, kind: Option<&str>, subaccount_id: Option<i32>, ) -> Result<Vec<Position>, HttpError>
Get positions
Retrieves user positions for the specified currency and kind.
§Arguments
currency- Currency filter (BTC, ETH, USDC, etc.) - optionalkind- Kind filter (future, option, spot, etc.) - optionalsubaccount_id- Subaccount ID - optional
§Examples
use deribit_http::DeribitHttpClient;
let client = DeribitHttpClient::new();
// let positions = client.get_positions(Some("BTC"), Some("future"), None).await?;
// println!("Found {} positions", positions.len());Sourcepub async fn get_position(
&self,
instrument_name: &str,
) -> Result<Vec<Position>, HttpError>
pub async fn get_position( &self, instrument_name: &str, ) -> Result<Vec<Position>, HttpError>
Sourcepub async fn edit_order(
&self,
request: OrderRequest,
) -> Result<OrderResponse, HttpError>
pub async fn edit_order( &self, request: OrderRequest, ) -> Result<OrderResponse, HttpError>
Sourcepub async fn mass_quote(
&self,
_quotes: MassQuoteRequest,
) -> Result<MassQuoteResponse, HttpError>
pub async fn mass_quote( &self, _quotes: MassQuoteRequest, ) -> Result<MassQuoteResponse, HttpError>
Sourcepub async fn get_user_trades_by_instrument(
&self,
instrument_name: &str,
start_seq: Option<u64>,
end_seq: Option<u64>,
count: Option<u32>,
include_old: Option<bool>,
sorting: Option<&str>,
) -> Result<UserTradeWithPaginationResponse, HttpError>
pub async fn get_user_trades_by_instrument( &self, instrument_name: &str, start_seq: Option<u64>, end_seq: Option<u64>, count: Option<u32>, include_old: Option<bool>, sorting: Option<&str>, ) -> Result<UserTradeWithPaginationResponse, HttpError>
Get user trades by instrument
Retrieves user trades for a specific instrument.
§Arguments
instrument_name- Instrument namestart_seq- Start sequence number (optional)end_seq- End sequence number (optional)count- Number of requested items (optional)include_old- Include old trades (optional)sorting- Direction of results sorting (optional)
Sourcepub async fn cancel_quotes(
&self,
cancel_type: Option<&str>,
) -> Result<u32, HttpError>
pub async fn cancel_quotes( &self, cancel_type: Option<&str>, ) -> Result<u32, HttpError>
Cancel quotes
Cancels all mass quotes.
§Arguments
cancel_type- Type of cancellation (“all”, “by_currency”, “by_instrument”, etc.)
Sourcepub async fn get_open_orders(
&self,
kind: Option<&str>,
order_type: Option<&str>,
) -> Result<Vec<OrderInfoResponse>, HttpError>
pub async fn get_open_orders( &self, kind: Option<&str>, order_type: Option<&str>, ) -> Result<Vec<OrderInfoResponse>, HttpError>
Get open orders
Retrieves list of user’s open orders across many currencies.
§Arguments
kind- Instrument kind filter (optional)order_type- Order type filter (optional)
Sourcepub async fn get_open_orders_by_label(
&self,
label: &str,
currency: &str,
) -> Result<Vec<OrderInfoResponse>, HttpError>
pub async fn get_open_orders_by_label( &self, label: &str, currency: &str, ) -> Result<Vec<OrderInfoResponse>, HttpError>
Get open orders by label
Retrieves open orders filtered by a specific label.
§Arguments
label- The label to filter orders bycurrency- The currency symbol (BTC, ETH, etc.)
Sourcepub async fn get_order_state(
&self,
order_id: &str,
) -> Result<OrderInfoResponse, HttpError>
pub async fn get_order_state( &self, order_id: &str, ) -> Result<OrderInfoResponse, HttpError>
Sourcepub async fn get_open_orders_by_currency(
&self,
currency: &str,
kind: Option<&str>,
order_type: Option<&str>,
) -> Result<Vec<OrderInfoResponse>, HttpError>
pub async fn get_open_orders_by_currency( &self, currency: &str, kind: Option<&str>, order_type: Option<&str>, ) -> Result<Vec<OrderInfoResponse>, HttpError>
Get open orders by currency
Retrieves open orders for a specific currency.
§Arguments
currency- The currency symbol (BTC, ETH, etc.)kind- Instrument kind filter (optional)order_type- Order type filter (optional)
Sourcepub async fn get_open_orders_by_instrument(
&self,
instrument_name: &str,
order_type: Option<&str>,
) -> Result<Vec<OrderInfoResponse>, HttpError>
pub async fn get_open_orders_by_instrument( &self, instrument_name: &str, order_type: Option<&str>, ) -> Result<Vec<OrderInfoResponse>, HttpError>
Get open orders by instrument
Retrieves open orders for a specific instrument.
§Arguments
instrument_name- The instrument nameorder_type- Order type filter (optional)
Sourcepub async fn get_order_history(
&self,
currency: &str,
kind: Option<&str>,
count: Option<u32>,
offset: Option<u32>,
) -> Result<Vec<OrderInfoResponse>, HttpError>
pub async fn get_order_history( &self, currency: &str, kind: Option<&str>, count: Option<u32>, offset: Option<u32>, ) -> Result<Vec<OrderInfoResponse>, HttpError>
Get order history
Retrieves history of orders that have been partially or fully filled.
§Arguments
currency- Currency symbol (BTC, ETH, etc.)kind- Instrument kind filter (optional)count- Number of requested items (optional, default 20)offset- Offset for pagination (optional)
Sourcepub async fn get_order_history_by_currency(
&self,
currency: &str,
kind: Option<&str>,
count: Option<u32>,
offset: Option<u32>,
) -> Result<Vec<OrderInfoResponse>, HttpError>
pub async fn get_order_history_by_currency( &self, currency: &str, kind: Option<&str>, count: Option<u32>, offset: Option<u32>, ) -> Result<Vec<OrderInfoResponse>, HttpError>
Get order history by currency
Retrieves order history for a specific currency.
§Arguments
currency- Currency symbol (BTC, ETH, etc.)kind- Instrument kind filter (optional)count- Number of requested items (optional)offset- Offset for pagination (optional)
Sourcepub async fn get_order_history_by_instrument(
&self,
instrument_name: &str,
count: Option<u32>,
offset: Option<u32>,
) -> Result<Vec<OrderInfoResponse>, HttpError>
pub async fn get_order_history_by_instrument( &self, instrument_name: &str, count: Option<u32>, offset: Option<u32>, ) -> Result<Vec<OrderInfoResponse>, HttpError>
Get order history by instrument
Retrieves order history for a specific instrument.
§Arguments
instrument_name- The instrument namecount- Number of requested items (optional)offset- Offset for pagination (optional)
Sourcepub async fn get_user_trades_by_currency(
&self,
request: TradesRequest,
) -> Result<UserTradeWithPaginationResponse, HttpError>
pub async fn get_user_trades_by_currency( &self, request: TradesRequest, ) -> Result<UserTradeWithPaginationResponse, HttpError>
Get user trades by currency
Retrieves user trades filtered by currency.
§Arguments
request- ATradesRequeststruct containing:currency- Currency symbol (BTC, ETH, etc.)kind- Instrument kind filter (optional)start_id- The ID of the first trade to be returned (optional)end_id- The ID of the last trade to be returned (optional)count- Number of requested items (optional, default 10, max 1000)start_timestamp- The earliest timestamp to return results from (optional)end_timestamp- The most recent timestamp to return results from (optional)sorting- Direction of results sorting (optional)historical- If true, retrieves historical records that persist indefinitely. If false (default), retrieves recent records available for 24 hours.subaccount_id- The user id for the subaccount (optional)
Sourcepub async fn get_user_trades_by_currency_and_time(
&self,
request: TradesRequest,
) -> Result<UserTradeWithPaginationResponse, HttpError>
pub async fn get_user_trades_by_currency_and_time( &self, request: TradesRequest, ) -> Result<UserTradeWithPaginationResponse, HttpError>
Get user trades by currency and time
Retrieves user trades filtered by currency within a time range.
§Arguments
request- ATradesRequeststruct containing:currency- Currency symbol (BTC, ETH, etc.)kind- Instrument kind filter (optional)start_id- The ID of the first trade to be returned (optional)end_id- The ID of the last trade to be returned (optional)count- Number of requested items (optional, default 10, max 1000)start_timestamp- The earliest timestamp to return results from (optional)end_timestamp- The most recent timestamp to return results from (optional)sorting- Direction of results sorting (optional)historical- If true, retrieves historical records that persist indefinitely. If false (default), retrieves recent records available for 24 hours.subaccount_id- The user id for the subaccount (optional)
Sourcepub async fn get_user_trades_by_instrument_and_time(
&self,
instrument_name: &str,
start_timestamp: u64,
end_timestamp: u64,
count: Option<u32>,
include_old: Option<bool>,
sorting: Option<&str>,
) -> Result<UserTradeWithPaginationResponse, HttpError>
pub async fn get_user_trades_by_instrument_and_time( &self, instrument_name: &str, start_timestamp: u64, end_timestamp: u64, count: Option<u32>, include_old: Option<bool>, sorting: Option<&str>, ) -> Result<UserTradeWithPaginationResponse, HttpError>
Get user trades by instrument and time
Retrieves user trades for a specific instrument within a time range.
§Arguments
instrument_name- Instrument namestart_timestamp- Start timestamp in millisecondsend_timestamp- End timestamp in millisecondscount- Number of requested items (optional, default 10)include_old- Include trades older than 7 days (optional)sorting- Direction of results sorting (optional)
Sourcepub async fn get_user_trades_by_order(
&self,
order_id: &str,
sorting: Option<&str>,
historical: bool,
) -> Result<Vec<UserTradeResponseByOrder>, HttpError>
pub async fn get_user_trades_by_order( &self, order_id: &str, sorting: Option<&str>, historical: bool, ) -> Result<Vec<UserTradeResponseByOrder>, HttpError>
Get user trades by order
Retrieves user trades for a specific order.
§Arguments
order_id- Order IDsorting- Direction of results sorting (optional)
Source§impl DeribitHttpClient
Market data endpoints
impl DeribitHttpClient
Market data endpoints
Sourcepub async fn get_currencies(&self) -> Result<Vec<CurrencyStruct>, HttpError>
pub async fn get_currencies(&self) -> Result<Vec<CurrencyStruct>, HttpError>
Get all supported currencies
Retrieves all cryptocurrencies supported by the API. This is a public endpoint that doesn’t require authentication.
§Examples
let client = DeribitHttpClient::new(); // testnet
let currencies = client.get_currencies().await?;
for currency in currencies {
println!("Currency: {} ({})", currency.currency, currency.currency_long);
}Sourcepub async fn get_index(&self, currency: &str) -> Result<IndexData, HttpError>
pub async fn get_index(&self, currency: &str) -> Result<IndexData, HttpError>
Get current index price for a currency
Retrieves the current index price for the instruments, for the selected currency. This is a public endpoint that doesn’t require authentication.
§Arguments
currency- The currency symbol (BTC, ETH, USDC, USDT, EURR)
Sourcepub async fn get_index_price(
&self,
index_name: &str,
) -> Result<IndexPriceData, HttpError>
pub async fn get_index_price( &self, index_name: &str, ) -> Result<IndexPriceData, HttpError>
Get index price by name
Retrieves the current index price value for given index name. This is a public endpoint that doesn’t require authentication.
§Arguments
index_name- The index identifier (e.g., “btc_usd”, “eth_usd”)
§Examples
let client = DeribitHttpClient::new(); // testnet
let index_price = client.get_index_price("btc_usd").await?;
println!("Index price: {}", index_price.index_price);Sourcepub async fn get_index_price_names(&self) -> Result<Vec<String>, HttpError>
pub async fn get_index_price_names(&self) -> Result<Vec<String>, HttpError>
Get all supported index price names
Retrieves the identifiers of all supported Price Indexes. This is a public endpoint that doesn’t require authentication.
§Examples
let client = DeribitHttpClient::new(); // testnet
let index_names = client.get_index_price_names().await?;
for name in index_names {
println!("Index: {}", name);
}Sourcepub async fn get_book_summary_by_currency(
&self,
currency: &str,
kind: Option<&str>,
) -> Result<Vec<BookSummary>, HttpError>
pub async fn get_book_summary_by_currency( &self, currency: &str, kind: Option<&str>, ) -> Result<Vec<BookSummary>, HttpError>
Get book summary by currency
Retrieves the summary information such as open interest, 24h volume, etc. for all instruments for the currency (optionally filtered by kind). This is a public endpoint that doesn’t require authentication.
§Arguments
currency- The currency symbol (BTC, ETH, USDC, USDT, EURR)kind- Optional instrument kind filter (future, option, spot, future_combo, option_combo)
§Examples
let client = DeribitHttpClient::new(); // testnet
let summaries = client.get_book_summary_by_currency("BTC", Some("future")).await?;
for summary in summaries {
println!("Instrument: {} - Volume: {}", summary.instrument_name, summary.volume);
}Sourcepub async fn get_instrument(
&self,
instrument_name: &str,
) -> Result<Instrument, HttpError>
pub async fn get_instrument( &self, instrument_name: &str, ) -> Result<Instrument, HttpError>
Get single instrument information
Retrieves detailed information about a specific instrument. This is a public endpoint that doesn’t require authentication.
§Arguments
instrument_name- The instrument identifier (e.g., “BTC-PERPETUAL”)
§Examples
let client = DeribitHttpClient::new(); // testnet
let instrument = client.get_instrument("BTC-PERPETUAL").await?;
println!("Contract size: {:?}", instrument.contract_size);Sourcepub async fn get_book_summary_by_instrument(
&self,
instrument_name: &str,
) -> Result<BookSummary, HttpError>
pub async fn get_book_summary_by_instrument( &self, instrument_name: &str, ) -> Result<BookSummary, HttpError>
Get book summary by instrument
Retrieves the summary information such as open interest, 24h volume, etc. for a specific instrument. This is a public endpoint that doesn’t require authentication.
§Arguments
instrument_name- The instrument identifier (e.g., “BTC-PERPETUAL”)
Sourcepub async fn get_contract_size(
&self,
instrument_name: &str,
) -> Result<f64, HttpError>
pub async fn get_contract_size( &self, instrument_name: &str, ) -> Result<f64, HttpError>
Get contract size for an instrument
Retrieves contract size for specified instrument. This is a public endpoint that doesn’t require authentication.
§Arguments
instrument_name- The instrument identifier (e.g., “BTC-PERPETUAL”)
§Examples
let client = DeribitHttpClient::new(); // testnet
let contract_size = client.get_contract_size("BTC-PERPETUAL").await?;
println!("Contract size: {}", contract_size);Sourcepub async fn get_server_time(&self) -> Result<u64, HttpError>
pub async fn get_server_time(&self) -> Result<u64, HttpError>
Get server time
Returns the current server time in milliseconds since Unix epoch. This is a public endpoint that doesn’t require authentication.
§Examples
let client = DeribitHttpClient::new(); // testnet
let server_time = client.get_server_time().await?;
println!("Server time: {}", server_time);Sourcepub async fn test_connection(&self) -> Result<String, HttpError>
pub async fn test_connection(&self) -> Result<String, HttpError>
Test connectivity to the API
Returns the API version to test connectivity. This is a public endpoint that doesn’t require authentication.
Sourcepub async fn get_status(&self) -> Result<StatusResponse, HttpError>
pub async fn get_status(&self) -> Result<StatusResponse, HttpError>
Get platform status and locked currency indices
Returns information about the platform status and any locked currency indices. This is a public endpoint that doesn’t require authentication.
Sourcepub async fn get_apr_history(
&self,
currency: &str,
limit: Option<u32>,
before: Option<i32>,
) -> Result<AprHistoryResponse, HttpError>
pub async fn get_apr_history( &self, currency: &str, limit: Option<u32>, before: Option<i32>, ) -> Result<AprHistoryResponse, HttpError>
Get APR history for yield tokens
Retrieves historical APR data for specified currency. Only applicable to yield-generating tokens (USDE, STETH). This is a public endpoint that doesn’t require authentication.
§Arguments
currency- Currency for which to retrieve APR history (usde or steth)limit- Optional number of days to retrieve (default 365, maximum 365)before- Optional parameter to receive APR history before given epoch day
Sourcepub async fn get_ticker(
&self,
instrument_name: &str,
) -> Result<TickerData, HttpError>
pub async fn get_ticker( &self, instrument_name: &str, ) -> Result<TickerData, HttpError>
Get ticker information for an instrument
Returns ticker data including last price, bid/ask, volume, etc.
§Arguments
instrument_name- The instrument identifier (e.g., “BTC-PERPETUAL”)
§Examples
let client = DeribitHttpClient::new();
let ticker = client.get_ticker("BTC-PERPETUAL").await?;
println!("Last price: {:?}", ticker.last_price);Sourcepub async fn get_order_book(
&self,
instrument_name: &str,
depth: Option<u32>,
) -> Result<OrderBook, HttpError>
pub async fn get_order_book( &self, instrument_name: &str, depth: Option<u32>, ) -> Result<OrderBook, HttpError>
Get order book for an instrument
Returns the current order book with bids and asks.
§Arguments
instrument_name- The instrument identifierdepth- Optional depth of the order book (default: 5)
Sourcepub async fn get_options(
&self,
currency: &str,
expiry: &str,
) -> Result<Vec<OptionInstrument>, HttpError>
pub async fn get_options( &self, currency: &str, expiry: &str, ) -> Result<Vec<OptionInstrument>, HttpError>
Retrieves a list of option instruments for a given currency and expiry date.
This asynchronous function fetches option instruments for the specified currency
and expiry date and returns a filtered list of options along with their associated
ticker information.
§Arguments
currency- A string slice that represents the name of the currency (e.g., “BTC”, “ETH”).expiry- A string slice representing the expiry date for the options (e.g., “20231027”).
§Returns
Returns a Result containing a vector of OptionInstrument on success,
or an HttpError on failure.
- On success, it returns a
Vec<OptionInstrument>, where each option contains the instrument details and ticker information. - On failure, it returns an
HttpError, such as in cases where the instrument data could not be retrieved or tickers are inaccessible.
§Errors
This function may return an HttpError in the following scenarios:
- If fetching the instrument data fails.
- If retrieving ticker information for an instrument fails.
§Implementation Details
- Fetches instruments for the specified
currencyfiltered by typeoption. - Filters the instruments to ensure they match the
currency-expirybase name. - Constructs an
OptionInstrumentfor each filtered instrument, including the instrument details and ticker information.
Sourcepub async fn get_options_pair(
&self,
currency: &str,
expiry: &str,
) -> Result<HashMap<u64, OptionInstrumentPair>, HttpError>
pub async fn get_options_pair( &self, currency: &str, expiry: &str, ) -> Result<HashMap<u64, OptionInstrumentPair>, HttpError>
Fetches option instruments for a given currency and expiry date, grouped by strike price.
This method retrieves all option instruments for the specified currency and expiry,
then groups them into pairs (call and put) by strike price. Each strike price
maps to an OptionInstrumentPair containing the call and put options if available.
§Arguments
currency- The currency symbol (e.g., “BTC”, “ETH”)expiry- The expiry date in format “DDMMMYY” (e.g., “10SEP25”)
§Returns
Returns a HashMap where:
- Key: Strike price as
u64 - Value:
OptionInstrumentPaircontaining call and put options for that strike
§Errors
Returns HttpError if:
- The API request fails
- An option instrument has no option type
- Network or authentication errors occur
§Example
let client = DeribitHttpClient::new();
let pairs = client.get_options_pair("BTC", "10SEP25").await?;
for (strike, pair) in pairs {
println!("Strike {}: Call={:?}, Put={:?}",
strike, pair.call.is_some(), pair.put.is_some());
}Sourcepub async fn get_instruments(
&self,
currency: &str,
kind: Option<&str>,
expired: Option<bool>,
) -> Result<Vec<Instrument>, HttpError>
pub async fn get_instruments( &self, currency: &str, kind: Option<&str>, expired: Option<bool>, ) -> Result<Vec<Instrument>, HttpError>
Get available instruments
Returns a list of available trading instruments.
§Arguments
currency- The currency (e.g., “BTC”, “ETH”)kind- Optional instrument kind (“future”, “option”, “spot”)expired- Whether to include expired instruments
Sourcepub async fn get_last_trades(
&self,
instrument_name: &str,
count: Option<u32>,
include_old: Option<bool>,
) -> Result<Vec<Trade>, HttpError>
pub async fn get_last_trades( &self, instrument_name: &str, count: Option<u32>, include_old: Option<bool>, ) -> Result<Vec<Trade>, HttpError>
Get recent trades for an instrument
Returns recent trade history for the specified instrument.
§Arguments
instrument_name- The instrument identifiercount- Optional number of trades to return (default: 10, max: 1000)include_old- Whether to include old trades
Sourcepub async fn get_historical_volatility(
&self,
currency: &str,
) -> Result<Vec<[f64; 2]>, HttpError>
pub async fn get_historical_volatility( &self, currency: &str, ) -> Result<Vec<[f64; 2]>, HttpError>
Get historical volatility
Provides information about historical volatility for given cryptocurrency.
§Arguments
currency- Currency symbol (BTC, ETH, etc.)
§Examples
use deribit_http::DeribitHttpClient;
let client = DeribitHttpClient::new();
// let volatility = client.get_historical_volatility("BTC").await?;
// tracing::info!("Found {} volatility data points", volatility.len());Sourcepub async fn get_funding_chart_data(
&self,
instrument_name: &str,
length: &str,
) -> Result<FundingChartData, HttpError>
pub async fn get_funding_chart_data( &self, instrument_name: &str, length: &str, ) -> Result<FundingChartData, HttpError>
Get funding chart data
Retrieves the list of the latest PERPETUAL funding chart points within a given time period.
§Arguments
instrument_name- Instrument namelength- Time period (8h, 24h, 1m)
§Examples
use deribit_http::DeribitHttpClient;
let client = DeribitHttpClient::new();
// let funding_data = client.get_funding_chart_data("BTC-PERPETUAL", "8h").await?;
// tracing::info!("Current interest: {}", funding_data.current_interest);Sourcepub async fn get_tradingview_chart_data(
&self,
instrument_name: &str,
start_timestamp: u64,
end_timestamp: u64,
resolution: &str,
) -> Result<TradingViewChartData, HttpError>
pub async fn get_tradingview_chart_data( &self, instrument_name: &str, start_timestamp: u64, end_timestamp: u64, resolution: &str, ) -> Result<TradingViewChartData, HttpError>
Get TradingView chart data
Publicly available market data used to generate a TradingView candle chart.
§Arguments
instrument_name- Instrument namestart_timestamp- Start timestamp in millisecondsend_timestamp- End timestamp in millisecondsresolution- Chart resolution (1, 3, 5, 10, 15, 30, 60, 120, 180, 360)
§Examples
use deribit_http::DeribitHttpClient;
let client = DeribitHttpClient::new();
// let chart_data = client.get_tradingview_chart_data("BTC-PERPETUAL", 1554373800000, 1554376800000, "30").await?;
// tracing::info!("Chart status: {}", chart_data.status);Sourcepub async fn get_delivery_prices(
&self,
index_name: &str,
count: Option<u32>,
offset: Option<u32>,
) -> Result<DeliveryPricesResponse, HttpError>
pub async fn get_delivery_prices( &self, index_name: &str, count: Option<u32>, offset: Option<u32>, ) -> Result<DeliveryPricesResponse, HttpError>
Get delivery prices
Retrieves delivery prices for the given index. This is a public endpoint that doesn’t require authentication.
§Arguments
index_name- Index identifier (e.g., “btc_usd”, “eth_usd”)count- Number of requested items (optional, default 20)offset- Offset for pagination (optional, default 0)
§Examples
let client = DeribitHttpClient::new(); // testnet
let delivery_prices = client.get_delivery_prices("btc_usd", Some(5), Some(0)).await?;
for price in delivery_prices.data {
println!("Date: {} - Price: {}", price.date, price.delivery_price);
}Sourcepub async fn get_expirations(
&self,
currency: &str,
kind: &str,
currency_pair: Option<&str>,
) -> Result<ExpirationsResponse, HttpError>
pub async fn get_expirations( &self, currency: &str, kind: &str, currency_pair: Option<&str>, ) -> Result<ExpirationsResponse, HttpError>
Get expirations
Retrieves expirations for instruments. This method can be used to see instrument expirations. This is a public endpoint that doesn’t require authentication.
§Arguments
currency- The currency symbol (BTC, ETH, USDC, USDT, any, grouped)kind- Instrument kind (future, option, any)currency_pair- Currency pair identifier (optional)
Sourcepub async fn get_funding_rate_history(
&self,
instrument_name: &str,
start_timestamp: u64,
end_timestamp: u64,
) -> Result<Vec<FundingRateData>, HttpError>
pub async fn get_funding_rate_history( &self, instrument_name: &str, start_timestamp: u64, end_timestamp: u64, ) -> Result<Vec<FundingRateData>, HttpError>
Get funding rate history
Retrieves hourly historical interest rate for requested PERPETUAL instrument. This is a public endpoint that doesn’t require authentication.
§Arguments
instrument_name- Instrument namestart_timestamp- The earliest timestamp to return result from (milliseconds since UNIX epoch)end_timestamp- The most recent timestamp to return result from (milliseconds since UNIX epoch)
Sourcepub async fn get_funding_rate_value(
&self,
instrument_name: &str,
start_timestamp: u64,
end_timestamp: u64,
) -> Result<f64, HttpError>
pub async fn get_funding_rate_value( &self, instrument_name: &str, start_timestamp: u64, end_timestamp: u64, ) -> Result<f64, HttpError>
Get funding rate value
Retrieves interest rate value for requested period. Applicable only for PERPETUAL instruments. This is a public endpoint that doesn’t require authentication.
§Arguments
instrument_name- Instrument namestart_timestamp- The earliest timestamp to return result from (milliseconds since UNIX epoch)end_timestamp- The most recent timestamp to return result from (milliseconds since UNIX epoch)
§Examples
let client = DeribitHttpClient::new(); // testnet
let funding_rate = client.get_funding_rate_value("BTC-PERPETUAL", 1569888000000, 1569974400000).await?;
println!("Funding rate for period: {}", funding_rate);Sourcepub async fn get_last_settlements_by_currency(
&self,
currency: &str,
settlement_type: Option<&str>,
count: Option<u32>,
continuation: Option<&str>,
search_start_timestamp: Option<u64>,
) -> Result<SettlementsResponse, HttpError>
pub async fn get_last_settlements_by_currency( &self, currency: &str, settlement_type: Option<&str>, count: Option<u32>, continuation: Option<&str>, search_start_timestamp: Option<u64>, ) -> Result<SettlementsResponse, HttpError>
Get last settlements by currency
Retrieves historical settlement, delivery and bankruptcy events coming from all instruments within a given currency. This is a public endpoint that doesn’t require authentication.
§Arguments
currency- The currency symbol (BTC, ETH, USDC, USDT, EURR)settlement_type- Settlement type (settlement, delivery, bankruptcy) - optionalcount- Number of requested items (optional, default 20)continuation- Continuation token for pagination (optional)search_start_timestamp- The latest timestamp to return result from (optional)
Sourcepub async fn get_last_settlements_by_instrument(
&self,
instrument_name: &str,
settlement_type: Option<&str>,
count: Option<u32>,
continuation: Option<&str>,
search_start_timestamp: Option<u64>,
) -> Result<SettlementsResponse, HttpError>
pub async fn get_last_settlements_by_instrument( &self, instrument_name: &str, settlement_type: Option<&str>, count: Option<u32>, continuation: Option<&str>, search_start_timestamp: Option<u64>, ) -> Result<SettlementsResponse, HttpError>
Get last settlements by instrument
Retrieves historical public settlement, delivery and bankruptcy events filtered by instrument name. This is a public endpoint that doesn’t require authentication.
§Arguments
instrument_name- Instrument namesettlement_type- Settlement type (settlement, delivery, bankruptcy) - optionalcount- Number of requested items (optional, default 20)continuation- Continuation token for pagination (optional)search_start_timestamp- The latest timestamp to return result from (optional)
Sourcepub async fn get_last_trades_by_currency(
&self,
currency: &str,
kind: Option<&str>,
count: Option<u32>,
include_old: Option<bool>,
sorting: Option<&str>,
) -> Result<LastTradesResponse, HttpError>
pub async fn get_last_trades_by_currency( &self, currency: &str, kind: Option<&str>, count: Option<u32>, include_old: Option<bool>, sorting: Option<&str>, ) -> Result<LastTradesResponse, HttpError>
Get last trades by currency
Retrieves the latest trades that have occurred for instruments in a specific currency. This is a public endpoint that doesn’t require authentication.
§Arguments
currency- The currency symbol (BTC, ETH, USDC, USDT, EURR)kind- Instrument kind (future, option, spot, etc.) - optionalcount- Number of requested items (optional, default 10)include_old- Include trades older than 7 days (optional)sorting- Direction of results sorting (optional)
§Examples
let client = DeribitHttpClient::new(); // testnet
let trades = client.get_last_trades_by_currency("BTC", Some("future"), Some(10), Some(false), Some("desc")).await?;
for trade in trades.trades {
println!("Trade: {} {} at {}", trade.amount, trade.instrument_name, trade.price);
}Sourcepub async fn get_last_trades_by_currency_and_time(
&self,
currency: &str,
start_timestamp: u64,
end_timestamp: u64,
kind: Option<&str>,
count: Option<u32>,
include_old: Option<bool>,
sorting: Option<&str>,
) -> Result<LastTradesResponse, HttpError>
pub async fn get_last_trades_by_currency_and_time( &self, currency: &str, start_timestamp: u64, end_timestamp: u64, kind: Option<&str>, count: Option<u32>, include_old: Option<bool>, sorting: Option<&str>, ) -> Result<LastTradesResponse, HttpError>
Get last trades by currency and time
Retrieves the latest trades that have occurred for instruments in a specific currency within a time range. This is a public endpoint that doesn’t require authentication.
§Arguments
currency- The currency symbol (BTC, ETH, USDC, USDT, EURR)start_timestamp- The earliest timestamp to return result from (milliseconds since UNIX epoch)end_timestamp- The most recent timestamp to return result from (milliseconds since UNIX epoch)kind- Instrument kind (future, option, spot, etc.) - optionalcount- Number of requested items (optional, default 10)include_old- Include trades older than 7 days (optional)sorting- Direction of results sorting (optional)
§Examples
let client = DeribitHttpClient::new(); // testnet
let trades = client.get_last_trades_by_currency_and_time("BTC", 1569888000000, 1569974400000, Some("future"), Some(10), Some(false), Some("desc")).await?;
for trade in trades.trades {
println!("Trade: {} {} at {}", trade.amount, trade.instrument_name, trade.price);
}Sourcepub async fn get_last_trades_by_instrument_and_time(
&self,
instrument_name: &str,
start_timestamp: u64,
end_timestamp: u64,
count: Option<u32>,
include_old: Option<bool>,
sorting: Option<&str>,
) -> Result<LastTradesResponse, HttpError>
pub async fn get_last_trades_by_instrument_and_time( &self, instrument_name: &str, start_timestamp: u64, end_timestamp: u64, count: Option<u32>, include_old: Option<bool>, sorting: Option<&str>, ) -> Result<LastTradesResponse, HttpError>
Get last trades by instrument and time
Retrieves the latest trades that have occurred for a specific instrument within a time range. This is a public endpoint that doesn’t require authentication.
§Arguments
instrument_name- Instrument namestart_timestamp- The earliest timestamp to return result from (milliseconds since UNIX epoch)end_timestamp- The most recent timestamp to return result from (milliseconds since UNIX epoch)count- Number of requested items (optional, default 10)include_old- Include trades older than 7 days (optional)sorting- Direction of results sorting (optional)
§Examples
let client = DeribitHttpClient::new(); // testnet
let trades = client.get_last_trades_by_instrument_and_time("BTC-PERPETUAL", 1569888000000, 1569974400000, Some(10), Some(false), Some("desc")).await?;
for trade in trades.trades {
println!("Trade: {} at {} ({})", trade.amount, trade.price, trade.direction);
}Sourcepub async fn get_order_book_by_instrument_id(
&self,
instrument_id: u32,
depth: Option<u32>,
) -> Result<OrderBook, HttpError>
pub async fn get_order_book_by_instrument_id( &self, instrument_id: u32, depth: Option<u32>, ) -> Result<OrderBook, HttpError>
Get order book by instrument ID
Retrieves the order book for the specified instrument by its ID. This is a public endpoint that doesn’t require authentication.
§Arguments
instrument_id- Instrument IDdepth- The number of entries to return for bid and ask order book entries (optional)
§Examples
let client = DeribitHttpClient::new(); // testnet
let order_book = client.get_order_book_by_instrument_id(42, Some(5)).await?;
println!("Order book for {}: {} bids, {} asks",
order_book.instrument_name,
order_book.bids.len(),
order_book.asks.len());Trait Implementations§
Source§impl Clone for DeribitHttpClient
impl Clone for DeribitHttpClient
Source§fn clone(&self) -> DeribitHttpClient
fn clone(&self) -> DeribitHttpClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more