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_trades(
&self,
instrument_id: InstrumentId,
start: Option<DateTime<Utc>>,
end: Option<DateTime<Utc>>,
limit: Option<u32>,
) -> Result<Vec<TradeTick>>
pub async fn request_trades( &self, instrument_id: InstrumentId, start: Option<DateTime<Utc>>, end: Option<DateTime<Utc>>, limit: Option<u32>, ) -> Result<Vec<TradeTick>>
Requests historical trades for an instrument within a time range.
Fetches trade ticks from Deribit and converts them to Nautilus [TradeTick] objects.
§Arguments
instrument_id- The instrument to fetch trades forstart- Optional start time filterend- Optional end time filterlimit- Optional limit on number of trades (max 1000)
§Errors
Returns an error if:
- The request fails
- Trade parsing fails
Sourcepub async fn request_bars(
&self,
bar_type: BarType,
start: Option<DateTime<Utc>>,
end: Option<DateTime<Utc>>,
_limit: Option<u32>,
) -> Result<Vec<Bar>>
pub async fn request_bars( &self, bar_type: BarType, start: Option<DateTime<Utc>>, end: Option<DateTime<Utc>>, _limit: Option<u32>, ) -> Result<Vec<Bar>>
Requests historical bars (OHLCV) for an instrument.
Uses the public/get_tradingview_chart_data endpoint to fetch candlestick data.
§Errors
Returns an error if:
- Aggregation source is not EXTERNAL
- Bar aggregation type is not supported by Deribit
- The request fails or response cannot be parsed
§Supported Resolutions
Deribit supports: 1, 3, 5, 10, 15, 30, 60, 120, 180, 360, 720 minutes, and 1D (daily)
Sourcepub async fn request_book_snapshot(
&self,
instrument_id: InstrumentId,
depth: Option<u32>,
) -> Result<OrderBook>
pub async fn request_book_snapshot( &self, instrument_id: InstrumentId, depth: Option<u32>, ) -> Result<OrderBook>
Requests a snapshot of the order book for an instrument.
Fetches the order book from Deribit and converts it to a Nautilus [OrderBook].
§Arguments
instrument_id- The instrument to fetch the order book fordepth- Optional depth limit (valid values: 1, 5, 10, 20, 50, 100, 1000, 10000)
§Errors
Returns an error if:
- The request fails
- Order book parsing fails
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.
Sourcepub fn is_testnet(&self) -> bool
pub fn is_testnet(&self) -> bool
Returns whether this client is connected to testnet.
Source§impl DeribitHttpClient
impl DeribitHttpClient
pub fn py_is_testnet(&self) -> bool
pub fn py_is_initialized(&self) -> bool
Sourcepub fn py_cache_instruments(
&self,
py: Python<'_>,
instruments: Vec<Py<PyAny>>,
) -> PyResult<()>
pub fn py_cache_instruments( &self, py: Python<'_>, instruments: Vec<Py<PyAny>>, ) -> PyResult<()>
§Errors
Returns a Python exception if adding the instruments to the cache fails.
Sourcepub fn py_cache_instrument(
&self,
py: Python<'_>,
instrument: Py<PyAny>,
) -> PyResult<()>
pub fn py_cache_instrument( &self, py: Python<'_>, instrument: Py<PyAny>, ) -> PyResult<()>
§Errors
Returns a Python exception if adding the instrument to the cache fails.
Trait Implementations§
Source§impl Clone for DeribitHttpClient
impl Clone for DeribitHttpClient
Source§impl Debug for DeribitHttpClient
impl Debug for DeribitHttpClient
Source§impl<'py> IntoPyObject<'py> for DeribitHttpClient
impl<'py> IntoPyObject<'py> for DeribitHttpClient
Source§type Target = DeribitHttpClient
type Target = DeribitHttpClient
Source§type Output = Bound<'py, <DeribitHttpClient as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <DeribitHttpClient as IntoPyObject<'py>>::Target>
Source§fn into_pyobject(
self,
py: Python<'py>,
) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
Source§impl PyClass for DeribitHttpClient
impl PyClass for DeribitHttpClient
Source§impl PyClassImpl for DeribitHttpClient
impl PyClassImpl for DeribitHttpClient
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§const IS_IMMUTABLE_TYPE: bool = false
const IS_IMMUTABLE_TYPE: bool = false
Source§const RAW_DOC: &'static CStr = /// 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.
const RAW_DOC: &'static CStr = /// 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.
Source§const DOC: &'static CStr
const DOC: &'static CStr
text_signature if a constructor is defined. Read moreSource§type ThreadChecker = SendablePyClass<DeribitHttpClient>
type ThreadChecker = SendablePyClass<DeribitHttpClient>
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny by default, and when you declare
#[pyclass(extends=PyDict)], it’s PyDict.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
Source§impl PyClassNewTextSignature for DeribitHttpClient
impl PyClassNewTextSignature for DeribitHttpClient
const TEXT_SIGNATURE: &'static str = "(api_key=None, api_secret=None, base_url=None, is_testnet=False, timeout_secs=None, max_retries=None, retry_delay_ms=None, retry_delay_max_ms=None, proxy_url=None)"
Source§impl PyMethods<DeribitHttpClient> for PyClassImplCollector<DeribitHttpClient>
impl PyMethods<DeribitHttpClient> for PyClassImplCollector<DeribitHttpClient>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for DeribitHttpClient
impl PyTypeInfo for DeribitHttpClient
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
§fn is_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_type_of(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type or a subclass of this type.§fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type.impl DerefToPyAny for DeribitHttpClient
impl ExtractPyClassWithClone for DeribitHttpClient
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§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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§impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self into an owned Python object, dropping type information.§fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
self into an owned Python object, dropping type information and unbinding it
from the 'py lifetime.§fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
self into a Python object. Read more§impl<'py, T> IntoPyObjectNautilusExt<'py> for Twhere
T: IntoPyObjectExt<'py>,
impl<'py, T> IntoPyObjectNautilusExt<'py> for Twhere
T: IntoPyObjectExt<'py>,
§fn into_py_any_unwrap(self, py: Python<'py>) -> Py<PyAny>
fn into_py_any_unwrap(self, py: Python<'py>) -> Py<PyAny>
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> PyErrArguments for T
impl<T> PyErrArguments for T
§impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
§const NAME: &'static str = T::NAME
const NAME: &'static str = T::NAME
§fn type_check(object: &Bound<'_, PyAny>) -> bool
fn type_check(object: &Bound<'_, PyAny>) -> bool
§fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>
fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>
isinstance and issubclass function. Read more