pub struct DeriveWebSocketClient { /* private fields */ }Expand description
WebSocket client for the Derive JSON-RPC stream.
Construct with Self::new (public-only) or Self::with_credentials
when private channels and signed actions are needed. Call Self::connect
before any subscribe call; Self::disconnect tears the connection down.
Implementations§
Source§impl DeriveWebSocketClient
impl DeriveWebSocketClient
Sourcepub fn new(
url: Option<String>,
environment: DeriveEnvironment,
transport_backend: TransportBackend,
proxy_url: Option<String>,
) -> Self
pub fn new( url: Option<String>, environment: DeriveEnvironment, transport_backend: TransportBackend, proxy_url: Option<String>, ) -> Self
Builds a public-only client. URL falls back to the environment default
when url is None.
Sourcepub fn with_credentials(
url: Option<String>,
environment: DeriveEnvironment,
transport_backend: TransportBackend,
proxy_url: Option<String>,
credentials: DeriveWsCredentials,
max_matching_requests_per_second: Option<u32>,
) -> Self
pub fn with_credentials( url: Option<String>, environment: DeriveEnvironment, transport_backend: TransportBackend, proxy_url: Option<String>, credentials: DeriveWsCredentials, max_matching_requests_per_second: Option<u32>, ) -> Self
Builds a client that will issue public/login on connect and replay
it after each reconnect.
max_matching_requests_per_second sets the matching-engine rate limit
for order writes; None applies the Trader-tier default. See
crate::common::rate_limit.
Sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
Returns true when credentials are configured and the venue has
confirmed the latest public/login. Cleared on reconnect.
Sourcepub fn is_active(&self) -> bool
pub fn is_active(&self) -> bool
Returns true while the underlying transport is in the active state.
Sourcepub async fn connect(&mut self) -> Result<()>
pub async fn connect(&mut self) -> Result<()>
Establishes the WebSocket connection and spawns the I/O handler task.
When credentials are configured, issues public/login and awaits the
venue’s acknowledgement before returning.
§Errors
Returns DeriveWsError::Transport for handshake failures and
propagates DeriveWsError::Auth / DeriveWsError::JsonRpc when
the login flow fails.
Sourcepub async fn disconnect(&mut self) -> Result<()>
pub async fn disconnect(&mut self) -> Result<()>
Disconnects the WebSocket connection and awaits the handler task.
§Errors
Returns DeriveWsError::Transport when the disconnect command
cannot be enqueued; the handler still tears down on signal.
Sourcepub async fn subscribe_ticker(
&self,
instrument_name: &str,
interval: &str,
) -> Result<()>
pub async fn subscribe_ticker( &self, instrument_name: &str, interval: &str, ) -> Result<()>
Subscribes to ticker_slim.{instrument_name}.{interval}. interval is the
millisecond cadence string the venue exposes (e.g. "100", "1000").
§Errors
Propagates JSON-RPC errors raised by the venue and transport-level failures.
Sourcepub async fn unsubscribe_ticker(
&self,
instrument_name: &str,
interval: &str,
) -> Result<()>
pub async fn unsubscribe_ticker( &self, instrument_name: &str, interval: &str, ) -> Result<()>
Unsubscribes from ticker_slim.{instrument_name}.{interval}.
§Errors
Propagates JSON-RPC errors raised by the venue and transport-level failures.
Sourcepub async fn subscribe_orderbook(
&self,
instrument_name: &str,
group: &str,
depth: &str,
) -> Result<()>
pub async fn subscribe_orderbook( &self, instrument_name: &str, group: &str, depth: &str, ) -> Result<()>
Subscribes to orderbook.{instrument_name}.{group}.{depth}.
§Errors
Propagates JSON-RPC errors raised by the venue and transport-level failures.
Sourcepub async fn unsubscribe_orderbook(
&self,
instrument_name: &str,
group: &str,
depth: &str,
) -> Result<()>
pub async fn unsubscribe_orderbook( &self, instrument_name: &str, group: &str, depth: &str, ) -> Result<()>
Unsubscribes from orderbook.{instrument_name}.{group}.{depth}.
§Errors
Propagates JSON-RPC errors raised by the venue and transport-level failures.
Sourcepub async fn subscribe_trades(
&self,
instrument_type: &str,
currency: &str,
) -> Result<()>
pub async fn subscribe_trades( &self, instrument_type: &str, currency: &str, ) -> Result<()>
Subscribes to trades.{instrument_type}.{currency}.
§Errors
Propagates JSON-RPC errors raised by the venue and transport-level failures.
Sourcepub async fn unsubscribe_trades(
&self,
instrument_type: &str,
currency: &str,
) -> Result<()>
pub async fn unsubscribe_trades( &self, instrument_type: &str, currency: &str, ) -> Result<()>
Unsubscribes from trades.{instrument_type}.{currency}.
§Errors
Propagates JSON-RPC errors raised by the venue and transport-level failures.
Sourcepub async fn subscribe_channels<C>(&self, channels: Vec<C>) -> Result<()>where
C: Into<DeriveWsChannel>,
pub async fn subscribe_channels<C>(&self, channels: Vec<C>) -> Result<()>where
C: Into<DeriveWsChannel>,
Subscribes to a list of channel topics in a single subscribe frame.
Used by the execution client to bulk-subscribe to the private
{subaccount_id}.orders, {subaccount_id}.trades, and
{subaccount_id}.balances channels after login.
§Errors
Propagates JSON-RPC errors raised by the venue and transport-level failures.
Sourcepub async fn unsubscribe_channels<C>(&self, channels: Vec<C>) -> Result<()>where
C: Into<DeriveWsChannel>,
pub async fn unsubscribe_channels<C>(&self, channels: Vec<C>) -> Result<()>where
C: Into<DeriveWsChannel>,
Unsubscribes from a list of channel topics in a single
unsubscribe frame.
§Errors
Propagates JSON-RPC errors raised by the venue and transport-level failures.
Sourcepub async fn next_event(&mut self) -> Option<DeriveWsMessage>
pub async fn next_event(&mut self) -> Option<DeriveWsMessage>
Returns the next event emitted by the handler.
Sourcepub fn subscription_count(&self) -> usize
pub fn subscription_count(&self) -> usize
Returns the count of channels the client currently has confirmed subscriptions for.
Sourcepub fn subscription_handle(&self) -> DeriveWebSocketSubscriptionHandle
pub fn subscription_handle(&self) -> DeriveWebSocketSubscriptionHandle
Returns a cloneable handle for issuing subscription commands.
Sourcepub fn execution_handle(&self) -> DeriveWsExecutionHandle
pub fn execution_handle(&self) -> DeriveWsExecutionHandle
Returns a cloneable handle for issuing signed private/* trading
requests.
The handle shares the client’s command channel, so it stays valid across reconnects (the channel is swapped behind a shared lock). Obtain it once and clone it into each order-submission task.
Sourcepub fn take_event_receiver(
&mut self,
) -> Option<UnboundedReceiver<DeriveWsMessage>>
pub fn take_event_receiver( &mut self, ) -> Option<UnboundedReceiver<DeriveWsMessage>>
Takes the event receiver from the client.
This lets the live data client own the receive loop while subscription
commands continue through Self::subscription_handle.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for DeriveWebSocketClient
impl !UnwindSafe for DeriveWebSocketClient
impl Freeze for DeriveWebSocketClient
impl Send for DeriveWebSocketClient
impl Sync for DeriveWebSocketClient
impl Unpin for DeriveWebSocketClient
impl UnsafeUnpin for DeriveWebSocketClient
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§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