pub struct WebSocketConnection { /* private fields */ }Expand description
Represents an active WebSocket connection to Bybit.
This struct encapsulates the WebSocket stream and provides methods for subscribing to ticker streams, receiving messages, and closing the connection.
Implementations§
Source§impl WebSocketConnection
impl WebSocketConnection
Sourcepub fn new(ws_stream: WebSocketStream<MaybeTlsStream<TcpStream>>) -> Self
pub fn new(ws_stream: WebSocketStream<MaybeTlsStream<TcpStream>>) -> Self
Creates a new BybitWebSocketConnection.
Sourcepub async fn subscribe_ticker<T: AsRef<str>>(
&mut self,
symbols: &[T],
) -> Result<(), Error>
pub async fn subscribe_ticker<T: AsRef<str>>( &mut self, symbols: &[T], ) -> Result<(), Error>
Subscribes to the ticker stream for the specified symbol IDs.
This method sends a subscription request to the Bybit WebSocket API for the specified symbol IDs. Each symbol ID is transformed into a ticker stream identifier before being sent.
§Parameters
symbols: A slice of symbol IDs to subscribe to.
§Errors
Returns a tungstenite::Error if the WebSocket subscription request fails.
Sourcepub async fn unsubscribe_ticker<T: AsRef<str>>(
&mut self,
symbols: &[T],
) -> Result<(), Error>
pub async fn unsubscribe_ticker<T: AsRef<str>>( &mut self, symbols: &[T], ) -> Result<(), Error>
Unsubscribes from the ticker stream for the specified symbol IDs.
This method sends an unsubscription request to the Bybit WebSocket API for the specified symbol IDs. Each symbol ID is transformed into a ticker stream identifier before being sent.
§Parameters
symbols: A slice of symbol IDs to unsubscribe from.
§Errors
Returns a tungstenite::Error if the WebSocket unsubscription request fails.
Trait Implementations§
Source§impl AssetInfoProvider for WebSocketConnection
impl AssetInfoProvider for WebSocketConnection
Source§type SubscriptionError = Error
type SubscriptionError = Error
Source§type ListeningError = ListeningError
type ListeningError = ListeningError
Source§fn subscribe<'life0, 'life1, 'async_trait>(
&'life0 mut self,
ids: &'life1 [String],
) -> Pin<Box<dyn Future<Output = Result<(), Self::SubscriptionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn subscribe<'life0, 'life1, 'async_trait>(
&'life0 mut self,
ids: &'life1 [String],
) -> Pin<Box<dyn Future<Output = Result<(), Self::SubscriptionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Auto Trait Implementations§
impl !Freeze for WebSocketConnection
impl !RefUnwindSafe for WebSocketConnection
impl !UnwindSafe for WebSocketConnection
impl Send for WebSocketConnection
impl Sync for WebSocketConnection
impl Unpin for WebSocketConnection
impl UnsafeUnpin for WebSocketConnection
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
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request