Skip to main content

DeriveWebSocketClient

Struct DeriveWebSocketClient 

Source
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

Source

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.

Source

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>, max_per_instrument_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 shared wallet matching allowance. max_per_instrument_matching_requests_per_second sets the independent token refill rate for perpetuals, spot, and options. Unset values preserve existing shared settings or use reference defaults. Clients for the same wallet on the same API host share the first explicit settings. See crate::common::rate_limit.

Source

pub fn with_socket_control(self, control: SocketControl) -> Self

Configures socket state reporting and reconnect control.

Source

pub fn url(&self) -> &str

Returns the configured WebSocket URL.

Source

pub fn set_request_timeout(&mut self, timeout: Duration)

Sets the per-operation WebSocket timeout (login, subscribe, reads, writes).

Must be called before connect(). Defaults to WS_REQUEST_TIMEOUT.

Source

pub fn is_authenticated(&self) -> bool

Returns true when credentials are configured and the venue has confirmed the latest public/login. Cleared on reconnect.

Source

pub fn is_active(&self) -> bool

Returns true while the underlying transport is in the active state.

Source

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 an error if the WebSocket handshake or login flow fails.

Source

pub async fn disconnect(&mut self) -> Result<()>

Disconnects the WebSocket connection and awaits the handler task.

§Errors

Returns an error if the disconnect command cannot be enqueued; the handler still tears down on signal.

Source

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

Returns an error if the venue raises a JSON-RPC error or the transport fails.

Source

pub async fn unsubscribe_ticker( &self, instrument_name: &str, interval: &str, ) -> Result<()>

Unsubscribes from ticker_slim.{instrument_name}.{interval}.

§Errors

Returns an error if the venue raises a JSON-RPC error or the transport fails.

Source

pub async fn subscribe_orderbook( &self, instrument_name: &str, group: &str, depth: &str, ) -> Result<()>

Subscribes to orderbook.{instrument_name}.{group}.{depth}.

§Errors

Returns an error if the venue raises a JSON-RPC error or the transport fails.

Source

pub async fn unsubscribe_orderbook( &self, instrument_name: &str, group: &str, depth: &str, ) -> Result<()>

Unsubscribes from orderbook.{instrument_name}.{group}.{depth}.

§Errors

Returns an error if the venue raises a JSON-RPC error or the transport fails.

Source

pub async fn subscribe_trades( &self, instrument_type: &str, currency: &str, ) -> Result<()>

Subscribes to trades.{instrument_type}.{currency}.

§Errors

Returns an error if the venue raises a JSON-RPC error or the transport fails.

Source

pub async fn unsubscribe_trades( &self, instrument_type: &str, currency: &str, ) -> Result<()>

Unsubscribes from trades.{instrument_type}.{currency}.

§Errors

Returns an error if the venue raises a JSON-RPC error or the transport fails.

Source

pub async fn subscribe_channels<C>(&self, channels: Vec<C>) -> Result<()>

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

Returns an error if the venue raises a JSON-RPC error or the transport fails.

Source

pub async fn unsubscribe_channels<C>(&self, channels: Vec<C>) -> Result<()>

Unsubscribes from a list of channel topics in a single unsubscribe frame.

§Errors

Returns an error if the venue raises a JSON-RPC error or the transport fails.

Source

pub async fn next_event(&mut self) -> Option<DeriveWsMessage>

Returns the next event emitted by the handler.

Source

pub fn subscription_count(&self) -> usize

Returns the count of channels the client currently has confirmed subscriptions for.

Source

pub fn subscription_handle(&self) -> DeriveWebSocketSubscriptionHandle

Returns a cloneable handle for issuing subscription commands.

Source

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.

Source

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§

Source§

impl Debug for DeriveWebSocketClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for DeriveWebSocketClient

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Ungil for T
where T: Send,

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more