pub struct BinanceWs { /* private fields */ }Expand description
Binance WebSocket client wrapper
Implementations§
Source§impl BinanceWs
impl BinanceWs
Sourcepub fn new_with_auth(url: String, binance: Arc<Binance>) -> Self
pub fn new_with_auth(url: String, binance: Arc<Binance>) -> Self
Creates a WebSocket client with a listen key manager
Sourcepub async fn disconnect(&self) -> Result<()>
pub async fn disconnect(&self) -> Result<()>
Disconnects from the WebSocket server
Sourcepub async fn connect_user_stream(&self) -> Result<()>
pub async fn connect_user_stream(&self) -> Result<()>
Connects to the user data stream
Sourcepub async fn close_user_stream(&self) -> Result<()>
pub async fn close_user_stream(&self) -> Result<()>
Closes the user data stream
Sourcepub async fn get_listen_key(&self) -> Option<String>
pub async fn get_listen_key(&self) -> Option<String>
Returns the active listen key, when available
Sourcepub async fn subscribe_ticker(&self, symbol: &str) -> Result<()>
pub async fn subscribe_ticker(&self, symbol: &str) -> Result<()>
Subscribes to the ticker stream for a symbol
Sourcepub async fn subscribe_all_tickers(&self) -> Result<()>
pub async fn subscribe_all_tickers(&self) -> Result<()>
Subscribes to the 24-hour ticker stream for all symbols
Sourcepub async fn subscribe_trades(&self, symbol: &str) -> Result<()>
pub async fn subscribe_trades(&self, symbol: &str) -> Result<()>
Subscribes to real-time trade executions for a symbol
Sourcepub async fn subscribe_agg_trades(&self, symbol: &str) -> Result<()>
pub async fn subscribe_agg_trades(&self, symbol: &str) -> Result<()>
Subscribes to the aggregated trade stream for a symbol
Sourcepub async fn subscribe_orderbook(
&self,
symbol: &str,
levels: u32,
update_speed: &str,
) -> Result<()>
pub async fn subscribe_orderbook( &self, symbol: &str, levels: u32, update_speed: &str, ) -> Result<()>
Subscribes to the order book depth stream
Sourcepub async fn subscribe_orderbook_diff(
&self,
symbol: &str,
update_speed: Option<&str>,
) -> Result<()>
pub async fn subscribe_orderbook_diff( &self, symbol: &str, update_speed: Option<&str>, ) -> Result<()>
Subscribes to the diff order book stream
Sourcepub async fn subscribe_kline(&self, symbol: &str, interval: &str) -> Result<()>
pub async fn subscribe_kline(&self, symbol: &str, interval: &str) -> Result<()>
Subscribes to Kline (candlestick) data for a symbol
Sourcepub async fn subscribe_mini_ticker(&self, symbol: &str) -> Result<()>
pub async fn subscribe_mini_ticker(&self, symbol: &str) -> Result<()>
Subscribes to the mini ticker stream for a symbol
Sourcepub async fn subscribe_all_mini_tickers(&self) -> Result<()>
pub async fn subscribe_all_mini_tickers(&self) -> Result<()>
Subscribes to the mini ticker stream for all symbols
Sourcepub async fn unsubscribe(&self, stream: String) -> Result<()>
pub async fn unsubscribe(&self, stream: String) -> Result<()>
Cancels an existing subscription
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Indicates whether the WebSocket connection is active
Sourcepub fn state(&self) -> WsConnectionState
pub fn state(&self) -> WsConnectionState
Returns the current connection state.
Sourcepub fn subscriptions(&self) -> Vec<String>
pub fn subscriptions(&self) -> Vec<String>
Returns the list of active subscriptions.
Returns a vector of subscription channel names that are currently active. This method retrieves the actual subscriptions from the underlying WsClient’s subscription manager, providing accurate state tracking.
Sourcepub fn subscription_count(&self) -> usize
pub fn subscription_count(&self) -> usize
Returns the number of active subscriptions.
Sourcepub async fn get_cached_ticker(&self, symbol: &str) -> Option<Ticker>
pub async fn get_cached_ticker(&self, symbol: &str) -> Option<Ticker>
Returns cached ticker snapshot
Sourcepub async fn get_all_cached_tickers(&self) -> HashMap<String, Ticker>
pub async fn get_all_cached_tickers(&self) -> HashMap<String, Ticker>
Returns all cached ticker snapshots