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
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
Creates or retrieves a listen key, connects to the user data WebSocket, and starts auto-refresh
§Returns
Result of the connection attempt
§Errors
- Listen key manager is missing (requires
new_with_authconstructor) - Listen key creation failed
- WebSocket connection failed
§Example
let binance = Arc::new(Binance::new(ExchangeConfig::default())?);
let ws = binance.create_authenticated_ws();
ws.connect_user_stream().await?;Sourcepub async fn close_user_stream(&self) -> Result<()>
pub async fn close_user_stream(&self) -> Result<()>
Closes the user data stream
Stops auto-refresh and deletes the listen key
§Returns
Result of the shutdown
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<()>
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<()>
Sourcepub async fn subscribe_agg_trades(&self, symbol: &str) -> Result<()>
pub async fn subscribe_agg_trades(&self, symbol: &str) -> Result<()>
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<()>
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<()>
Sourcepub async fn subscribe_mini_ticker(&self, symbol: &str) -> Result<()>
pub async fn subscribe_mini_ticker(&self, symbol: &str) -> Result<()>
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<()>
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Indicates whether the WebSocket connection is active
Sourcepub async fn get_cached_ticker(&self, symbol: &str) -> Option<Ticker>
pub async fn get_cached_ticker(&self, symbol: &str) -> Option<Ticker>
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
Auto Trait Implementations§
impl Freeze for BinanceWs
impl !RefUnwindSafe for BinanceWs
impl Send for BinanceWs
impl Sync for BinanceWs
impl Unpin for BinanceWs
impl !UnwindSafe for BinanceWs
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