pub struct ManagedWebsocket { /* private fields */ }Expand description
Auto-reconnecting WebSocket handle.
Send + Sync — safe to share across async tasks without a Mutex.
Subscribe/unsubscribe/order sends are fire-and-forget: the call queues a
command to the background task and returns. Server acknowledgements arrive
as WsEvent::Message on the event stream, matching standard CEX WS
conventions.
Dropping the handle (or calling stop) terminates the
background task immediately — even if it is mid-reconnect — via a separate
cancellation signal that bypasses the command queue.
Implementations§
Source§impl ManagedWebsocket
impl ManagedWebsocket
Sourcepub async fn connect(client: &Client) -> Result<ManagedWebsocket, WSErrors>
pub async fn connect(client: &Client) -> Result<ManagedWebsocket, WSErrors>
Open a managed (auto-reconnecting) WebSocket connection for the given
Client.
The returned handle manages reconnection with exponential backoff and replays subscriptions automatically.
§Example
let mut ws = ManagedWebsocket::connect(&client).call().await?;
ws.subscribe([Topic::agg_trade("BTC-USD")], None)?;Uses tokio::spawn on native targets.
Sourcepub async fn connect_with(
client: &Client,
config: ManagedWsConfig,
) -> Result<ManagedWebsocket, WSErrors>
pub async fn connect_with( client: &Client, config: ManagedWsConfig, ) -> Result<ManagedWebsocket, WSErrors>
Like connect but takes an explicit ManagedWsConfig.
Sourcepub async fn recv(&mut self) -> Option<WsEvent>
pub async fn recv(&mut self) -> Option<WsEvent>
Receive the next event from the WebSocket.
Returns None when the background task has stopped (after permanent
disconnection or stop).
Sourcepub fn subscribe(
&self,
topics: impl IntoIterator<Item = Topic>,
id: Option<RequestId>,
) -> Result<(), ManagedWsError>
pub fn subscribe( &self, topics: impl IntoIterator<Item = Topic>, id: Option<RequestId>, ) -> Result<(), ManagedWsError>
Subscribe to topics. The subscription is tracked and replayed on reconnect.
This is fire-and-forget — it queues the command to the background task.
The server’s subscribe acknowledgement arrives as a WsEvent::Message.
Sourcepub fn subscribe_raw(
&self,
topics: impl IntoIterator<Item = String>,
id: Option<RequestId>,
) -> Result<(), ManagedWsError>
pub fn subscribe_raw( &self, topics: impl IntoIterator<Item = String>, id: Option<RequestId>, ) -> Result<(), ManagedWsError>
Sourcepub fn unsubscribe(
&self,
topics: impl IntoIterator<Item = Topic>,
id: Option<RequestId>,
) -> Result<(), ManagedWsError>
pub fn unsubscribe( &self, topics: impl IntoIterator<Item = Topic>, id: Option<RequestId>, ) -> Result<(), ManagedWsError>
Unsubscribe from topics. Removes them from the replay list.
Sourcepub fn unsubscribe_raw(
&self,
topics: impl IntoIterator<Item = String>,
id: Option<RequestId>,
) -> Result<(), ManagedWsError>
pub fn unsubscribe_raw( &self, topics: impl IntoIterator<Item = String>, id: Option<RequestId>, ) -> Result<(), ManagedWsError>
Raw-string counterpart of unsubscribe.
Sourcepub fn order_place(
&self,
tx: impl Into<String>,
id: Option<RequestId>,
) -> Result<(), ManagedWsError>
pub fn order_place( &self, tx: impl Into<String>, id: Option<RequestId>, ) -> Result<(), ManagedWsError>
Place an order via WebSocket.
Sourcepub fn order_cancel(
&self,
tx: impl Into<String>,
id: Option<RequestId>,
) -> Result<(), ManagedWsError>
pub fn order_cancel( &self, tx: impl Into<String>, id: Option<RequestId>, ) -> Result<(), ManagedWsError>
Cancel an order via WebSocket.
Sourcepub fn place_order(
&self,
signed: &Transaction,
id: Option<RequestId>,
) -> Result<(), WSErrors>
pub fn place_order( &self, signed: &Transaction, id: Option<RequestId>, ) -> Result<(), WSErrors>
Place an order using a signed Transaction. Base64-encodes internally.
Returns a SDKResult-style error instead of ManagedWsError because
encoding can fail independently of the channel state.
Sourcepub fn cancel_order(
&self,
signed: &Transaction,
id: Option<RequestId>,
) -> Result<(), WSErrors>
pub fn cancel_order( &self, signed: &Transaction, id: Option<RequestId>, ) -> Result<(), WSErrors>
Cancel an order using a signed Transaction. Base64-encodes internally.