pub struct DeribitWebSocketClient { /* private fields */ }Expand description
WebSocket client for connecting to Deribit.
Implementations§
Source§impl DeribitWebSocketClient
impl DeribitWebSocketClient
Sourcepub fn new(
url: Option<String>,
api_key: Option<String>,
api_secret: Option<String>,
heartbeat_interval: Option<u64>,
is_testnet: bool,
) -> Result<Self>
pub fn new( url: Option<String>, api_key: Option<String>, api_secret: Option<String>, heartbeat_interval: Option<u64>, is_testnet: bool, ) -> Result<Self>
Creates a new DeribitWebSocketClient instance.
§Errors
Returns an error if only one of api_key or api_secret is provided.
Sourcepub fn new_public(is_testnet: bool) -> Result<Self>
pub fn new_public(is_testnet: bool) -> Result<Self>
Sourcepub fn with_credentials(is_testnet: bool) -> Result<Self>
pub fn with_credentials(is_testnet: bool) -> Result<Self>
Creates an authenticated client with credentials.
Uses environment variables to load credentials:
- Testnet:
DERIBIT_TESTNET_API_KEYandDERIBIT_TESTNET_API_SECRET - Mainnet:
DERIBIT_API_KEYandDERIBIT_API_SECRET
§Errors
Returns an error if credentials are not found in environment variables.
Sourcepub fn cancel_all_requests(&self)
pub fn cancel_all_requests(&self)
Cancel all pending WebSocket requests.
Sourcepub fn cancellation_token(&self) -> &CancellationToken
pub fn cancellation_token(&self) -> &CancellationToken
Returns the cancellation token for this client.
Sourcepub async fn wait_until_active(&self, timeout_secs: f64) -> DeribitWsResult<()>
pub async fn wait_until_active(&self, timeout_secs: f64) -> DeribitWsResult<()>
Waits until the client is active or timeout expires.
§Errors
Returns an error if the timeout expires before the client becomes active.
Sourcepub fn cache_instruments(&self, instruments: Vec<InstrumentAny>)
pub fn cache_instruments(&self, instruments: Vec<InstrumentAny>)
Caches instruments for use during message parsing.
Sourcepub fn cache_instrument(&self, instrument: InstrumentAny)
pub fn cache_instrument(&self, instrument: InstrumentAny)
Caches a single instrument.
Sourcepub async fn close(&self) -> DeribitWsResult<()>
pub async fn close(&self) -> DeribitWsResult<()>
Sourcepub fn stream(&mut self) -> impl Stream<Item = NautilusWsMessage> + 'static
pub fn stream(&mut self) -> impl Stream<Item = NautilusWsMessage> + 'static
Returns a stream of WebSocket messages.
§Panics
Panics if called before connect() or if called twice.
Sourcepub fn has_credentials(&self) -> bool
pub fn has_credentials(&self) -> bool
Returns whether the client has credentials configured.
Sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
Returns whether the client is authenticated.
Sourcepub async fn authenticate(
&self,
session_name: Option<&str>,
) -> DeribitWsResult<()>
pub async fn authenticate( &self, session_name: Option<&str>, ) -> DeribitWsResult<()>
Authenticates the WebSocket session with Deribit.
Uses the client_signature grant type with HMAC-SHA256 signature.
This must be called before subscribing to raw data streams.
§Arguments
session_name- Optional session name for session-scoped authentication. When provided, usessession:<name>scope which allows skippingaccess_tokenin subsequent private requests. WhenNone, uses defaultconnectionscope. Recommended to use session scope for order execution compatibility.
§Errors
Returns an error if:
- No credentials are configured
- The authentication request fails
- The authentication times out
Sourcepub async fn authenticate_session(&self) -> DeribitWsResult<()>
pub async fn authenticate_session(&self) -> DeribitWsResult<()>
Authenticates with session scope using default session name.
Convenience method equivalent to authenticate(Some("nautilus")).
Session-scoped authentication is recommended for order execution as it
allows skipping access_token in private method payloads.
§Errors
Returns an error if authentication fails.
Sourcepub async fn auth_state(&self) -> Option<AuthState>
pub async fn auth_state(&self) -> Option<AuthState>
Returns the current authentication state containing tokens.
Returns None if not authenticated or tokens haven’t been stored yet.
Sourcepub async fn access_token(&self) -> Option<String>
pub async fn access_token(&self) -> Option<String>
Returns the current access token if available.
Sourcepub async fn subscribe_trades(
&self,
instrument_id: InstrumentId,
interval: Option<DeribitUpdateInterval>,
) -> DeribitWsResult<()>
pub async fn subscribe_trades( &self, instrument_id: InstrumentId, interval: Option<DeribitUpdateInterval>, ) -> DeribitWsResult<()>
Sourcepub async fn subscribe_trades_raw(
&self,
instrument_id: InstrumentId,
) -> DeribitWsResult<()>
pub async fn subscribe_trades_raw( &self, instrument_id: InstrumentId, ) -> DeribitWsResult<()>
Subscribes to raw trade updates (requires authentication).
Convenience method equivalent to subscribe_trades(id, Some(DeribitUpdateInterval::Raw)).
§Errors
Returns an error if not authenticated or subscription fails.
Sourcepub async fn unsubscribe_trades(
&self,
instrument_id: InstrumentId,
interval: Option<DeribitUpdateInterval>,
) -> DeribitWsResult<()>
pub async fn unsubscribe_trades( &self, instrument_id: InstrumentId, interval: Option<DeribitUpdateInterval>, ) -> DeribitWsResult<()>
Unsubscribes from trade updates for an instrument.
§Errors
Returns an error if unsubscription fails.
Sourcepub async fn subscribe_book(
&self,
instrument_id: InstrumentId,
interval: Option<DeribitUpdateInterval>,
) -> DeribitWsResult<()>
pub async fn subscribe_book( &self, instrument_id: InstrumentId, interval: Option<DeribitUpdateInterval>, ) -> DeribitWsResult<()>
Sourcepub async fn subscribe_book_raw(
&self,
instrument_id: InstrumentId,
) -> DeribitWsResult<()>
pub async fn subscribe_book_raw( &self, instrument_id: InstrumentId, ) -> DeribitWsResult<()>
Subscribes to raw order book updates (requires authentication).
Convenience method equivalent to subscribe_book(id, Some(DeribitUpdateInterval::Raw)).
§Errors
Returns an error if not authenticated or subscription fails.
Sourcepub async fn unsubscribe_book(
&self,
instrument_id: InstrumentId,
interval: Option<DeribitUpdateInterval>,
) -> DeribitWsResult<()>
pub async fn unsubscribe_book( &self, instrument_id: InstrumentId, interval: Option<DeribitUpdateInterval>, ) -> DeribitWsResult<()>
Unsubscribes from order book updates for an instrument.
§Errors
Returns an error if unsubscription fails.
Sourcepub async fn subscribe_ticker(
&self,
instrument_id: InstrumentId,
interval: Option<DeribitUpdateInterval>,
) -> DeribitWsResult<()>
pub async fn subscribe_ticker( &self, instrument_id: InstrumentId, interval: Option<DeribitUpdateInterval>, ) -> DeribitWsResult<()>
Sourcepub async fn subscribe_ticker_raw(
&self,
instrument_id: InstrumentId,
) -> DeribitWsResult<()>
pub async fn subscribe_ticker_raw( &self, instrument_id: InstrumentId, ) -> DeribitWsResult<()>
Subscribes to raw ticker updates (requires authentication).
Convenience method equivalent to subscribe_ticker(id, Some(DeribitUpdateInterval::Raw)).
§Errors
Returns an error if not authenticated or subscription fails.
Sourcepub async fn unsubscribe_ticker(
&self,
instrument_id: InstrumentId,
interval: Option<DeribitUpdateInterval>,
) -> DeribitWsResult<()>
pub async fn unsubscribe_ticker( &self, instrument_id: InstrumentId, interval: Option<DeribitUpdateInterval>, ) -> DeribitWsResult<()>
Unsubscribes from ticker updates for an instrument.
§Errors
Returns an error if unsubscription fails.
Sourcepub async fn subscribe_quotes(
&self,
instrument_id: InstrumentId,
) -> DeribitWsResult<()>
pub async fn subscribe_quotes( &self, instrument_id: InstrumentId, ) -> DeribitWsResult<()>
Subscribes to quote (best bid/ask) updates for an instrument.
Note: Quote channel does not support interval parameter.
§Errors
Returns an error if subscription fails.
Sourcepub async fn unsubscribe_quotes(
&self,
instrument_id: InstrumentId,
) -> DeribitWsResult<()>
pub async fn unsubscribe_quotes( &self, instrument_id: InstrumentId, ) -> DeribitWsResult<()>
Unsubscribes from quote updates for an instrument.
§Errors
Returns an error if unsubscription fails.
Sourcepub async fn unsubscribe(&self, channels: Vec<String>) -> DeribitWsResult<()>
pub async fn unsubscribe(&self, channels: Vec<String>) -> DeribitWsResult<()>
Trait Implementations§
Source§impl Clone for DeribitWebSocketClient
impl Clone for DeribitWebSocketClient
Source§fn clone(&self) -> DeribitWebSocketClient
fn clone(&self) -> DeribitWebSocketClient
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for DeribitWebSocketClient
impl !RefUnwindSafe for DeribitWebSocketClient
impl Send for DeribitWebSocketClient
impl Sync for DeribitWebSocketClient
impl Unpin for DeribitWebSocketClient
impl !UnwindSafe for DeribitWebSocketClient
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)§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