pub struct WsSession { /* private fields */ }Expand description
One WebSocket connection to Bybit, kept alive in a task of its own.
Implementations§
Source§impl WsSession
impl WsSession
Sourcepub fn spawn(
http: BybitHttpClient,
stream: WsStream,
event_tx: AsyncSender<WsIncoming>,
options: WsOptions,
) -> Self
pub fn spawn( http: BybitHttpClient, stream: WsStream, event_tx: AsyncSender<WsIncoming>, options: WsOptions, ) -> Self
Starts the session. It connects at once, in the background; event_tx gets every frame.
Sourcepub fn dropped_events(&self) -> u64
pub fn dropped_events(&self) -> u64
How many frames were dropped because the reader’s channel was full.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Whether the link is up (and logged in, for the private stream).
Sourcepub async fn subscribe(
&self,
req_id: &str,
topic: &str,
) -> Result<(), BybitApiError>
pub async fn subscribe( &self, req_id: &str, topic: &str, ) -> Result<(), BybitApiError>
Subscribes to topic. The request is sent when the link is up and again after every reconnect. The answer of
the exchange comes as a WsIncoming::Ack carrying req_id.
§Errors
BybitApiError::Subscription when the session is gone.
Sourcepub async fn resubscribe(
&self,
req_id: &str,
topic: &str,
) -> Result<(), BybitApiError>
pub async fn resubscribe( &self, req_id: &str, topic: &str, ) -> Result<(), BybitApiError>
Asks the exchange for topic again: it is cancelled and subscribed anew under req_id, so an order book
topic sends a fresh snapshot. A reconnect restores it under the new req_id.
§Errors
BybitApiError::Subscription when the session is gone.
Sourcepub async fn unsubscribe(&self, topic: &str) -> Result<(), BybitApiError>
pub async fn unsubscribe(&self, topic: &str) -> Result<(), BybitApiError>
Cancels the subscription to topic and forgets it, so a reconnect does not restore it.
§Errors
BybitApiError::Subscription when the session is gone.