pub struct WsClient { /* private fields */ }Expand description
WebSocket client for public and private streams.
Implementations§
Source§impl WsClient
impl WsClient
Sourcepub async fn connect_public(
channel: WsChannel,
) -> Result<(Self, UnboundedReceiver<WsMessage>), BybitError>
pub async fn connect_public( channel: WsChannel, ) -> Result<(Self, UnboundedReceiver<WsMessage>), BybitError>
Create a new WebSocket client for public streams.
§Example
use bybit_client::ws::{WsClient, WsChannel};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (client, mut receiver) = WsClient::connect_public(WsChannel::PublicLinear).await?;
client.subscribe(&["orderbook.50.BTCUSDT"]).await?;
while let Some(msg) = receiver.recv().await {
println!("Received: {:?}", msg);
}
Ok(())
}Sourcepub async fn connect_private(
api_key: impl Into<String>,
api_secret: impl Into<String>,
) -> Result<(Self, UnboundedReceiver<WsMessage>), BybitError>
pub async fn connect_private( api_key: impl Into<String>, api_secret: impl Into<String>, ) -> Result<(Self, UnboundedReceiver<WsMessage>), BybitError>
Create a new WebSocket client for private streams (requires authentication).
§Example
use bybit_client::ws::{WsClient, WsChannel};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (client, mut receiver) = WsClient::connect_private(
"api_key",
"api_secret",
).await?;
client.subscribe(&["position", "order", "execution"]).await?;
while let Some(msg) = receiver.recv().await {
println!("Received: {:?}", msg);
}
Ok(())
}Sourcepub async fn connect_with_config(
config: ClientConfig,
channel: WsChannel,
) -> Result<(Self, UnboundedReceiver<WsMessage>), BybitError>
pub async fn connect_with_config( config: ClientConfig, channel: WsChannel, ) -> Result<(Self, UnboundedReceiver<WsMessage>), BybitError>
Create a new WebSocket client with custom configuration.
Sourcepub async fn unsubscribe(&self, topics: &[&str]) -> Result<(), BybitError>
pub async fn unsubscribe(&self, topics: &[&str]) -> Result<(), BybitError>
Unsubscribe from topics.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Check if the client is connected.
Sourcepub fn disconnect(&self)
pub fn disconnect(&self)
Disconnect and stop the client.
Sourcepub async fn subscribed_topics(&self) -> Vec<String>
pub async fn subscribed_topics(&self) -> Vec<String>
Get the list of subscribed topics.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WsClient
impl !RefUnwindSafe for WsClient
impl Send for WsClient
impl Sync for WsClient
impl Unpin for WsClient
impl !UnwindSafe for WsClient
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
Mutably borrows from an owned value. Read more