pub struct DeribitHttpClient { /* private fields */ }Expand description
High-level Deribit HTTP client with domain-level abstractions.
This client wraps the raw HTTP client and provides methods that use Nautilus domain types. It maintains an instrument cache for efficient lookups.
Implementations§
Source§impl DeribitHttpClient
impl DeribitHttpClient
Sourcepub fn new(
base_url: Option<String>,
is_testnet: bool,
timeout_secs: Option<u64>,
max_retries: Option<u32>,
retry_delay_ms: Option<u64>,
retry_delay_max_ms: Option<u64>,
proxy_url: Option<String>,
) -> Result<Self>
pub fn new( base_url: Option<String>, is_testnet: bool, timeout_secs: Option<u64>, max_retries: Option<u32>, retry_delay_ms: Option<u64>, retry_delay_max_ms: Option<u64>, proxy_url: Option<String>, ) -> Result<Self>
Creates a new DeribitHttpClient with default configuration.
§Parameters
base_url: Optional custom base URL (for testing)is_testnet: Whether to use the testnet environment
§Errors
Returns an error if the HTTP client cannot be created.
Sourcepub fn new_with_env(
api_key: Option<String>,
api_secret: Option<String>,
is_testnet: bool,
timeout_secs: Option<u64>,
max_retries: Option<u32>,
retry_delay_ms: Option<u64>,
retry_delay_max_ms: Option<u64>,
proxy_url: Option<String>,
) -> Result<Self>
pub fn new_with_env( api_key: Option<String>, api_secret: Option<String>, is_testnet: bool, timeout_secs: Option<u64>, max_retries: Option<u32>, retry_delay_ms: Option<u64>, retry_delay_max_ms: Option<u64>, proxy_url: Option<String>, ) -> Result<Self>
Creates a new DeribitHttpClient with credentials from environment variables.
If api_key or api_secret are not provided, they will be loaded from environment:
- Mainnet:
DERIBIT_API_KEY,DERIBIT_API_SECRET - Testnet:
DERIBIT_TESTNET_API_KEY,DERIBIT_TESTNET_API_SECRET
§Errors
Returns an error if:
- The HTTP client cannot be created
- Credentials are not provided and environment variables are not set
Sourcepub async fn request_instruments(
&self,
currency: DeribitCurrency,
kind: Option<DeribitInstrumentKind>,
) -> Result<Vec<InstrumentAny>>
pub async fn request_instruments( &self, currency: DeribitCurrency, kind: Option<DeribitInstrumentKind>, ) -> Result<Vec<InstrumentAny>>
Requests instruments for a specific currency.
§Errors
Returns an error if the request fails or instruments cannot be parsed.
Sourcepub async fn request_instrument(
&self,
instrument_id: InstrumentId,
) -> Result<InstrumentAny>
pub async fn request_instrument( &self, instrument_id: InstrumentId, ) -> Result<InstrumentAny>
Requests a specific instrument by its Nautilus instrument ID.
This is a high-level method that fetches the raw instrument data from Deribit
and converts it to a Nautilus InstrumentAny type.
§Errors
Returns an error if:
- The instrument name format is invalid (error code
-32602) - The instrument doesn’t exist (error code
13020) - Network or API errors occur
Sourcepub async fn request_account_state(
&self,
account_id: AccountId,
) -> Result<AccountState>
pub async fn request_account_state( &self, account_id: AccountId, ) -> Result<AccountState>
Requests account state for all currencies.
Fetches account balance and margin information for all currencies from Deribit
and converts it to Nautilus AccountState event.
§Errors
Returns an error if:
- The request fails
- Currency conversion fails
Sourcepub fn cache_instruments(&self, instruments: Vec<InstrumentAny>)
pub fn cache_instruments(&self, instruments: Vec<InstrumentAny>)
Caches instruments for later retrieval.
Sourcepub fn get_instrument(&self, symbol: &Ustr) -> Option<InstrumentAny>
pub fn get_instrument(&self, symbol: &Ustr) -> Option<InstrumentAny>
Retrieves a cached instrument by symbol.
Sourcepub fn is_cache_initialized(&self) -> bool
pub fn is_cache_initialized(&self) -> bool
Checks if the instrument cache has been initialized.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for DeribitHttpClient
impl !RefUnwindSafe for DeribitHttpClient
impl Send for DeribitHttpClient
impl Sync for DeribitHttpClient
impl Unpin for DeribitHttpClient
impl !UnwindSafe for DeribitHttpClient
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more