pub struct BinanceConnectionManager { /* private fields */ }Expand description
Manages multiple WebSocket connections for Binance to handle sharding and isolation.
Connections are organized by market type (Spot, Swap, Futures, Option) to ensure that each market type connects to the correct WebSocket endpoint.
Implementations§
Source§impl BinanceConnectionManager
impl BinanceConnectionManager
Sourcepub fn new(urls: BinanceUrls, is_sandbox: bool) -> Self
pub fn new(urls: BinanceUrls, is_sandbox: bool) -> Self
Creates a new connection manager with the given URLs.
Sourcepub fn production() -> Self
pub fn production() -> Self
Creates a new connection manager for production environment.
Sourcepub fn get_ws_url(&self, market_type: MarketType) -> &str
pub fn get_ws_url(&self, market_type: MarketType) -> &str
Returns the WebSocket URL for the given market type.
§URL Routing
MarketType::Spot→stream.binance.com(spot and margin trading)MarketType::Futures→fstream.binance.com(Linear/USDT-margined contracts)MarketType::Swap→dstream.binance.com(Inverse/Coin-margined contracts)MarketType::Option→nbstream.binance.com(European-style options)
Callers should select the MarketType based on the market’s linear/inverse flags:
market.linear == true→ useMarketType::Futuresmarket.inverse == true→ useMarketType::Swap
§Arguments
market_type- The market type to get the URL for
§Returns
The WebSocket URL for the specified market type.
Sourcepub async fn get_public_connection(
&self,
market_type: MarketType,
) -> Result<Arc<BinanceWs>>
pub async fn get_public_connection( &self, market_type: MarketType, ) -> Result<Arc<BinanceWs>>
Sourcepub async fn get_private_connection(
&self,
market_type: MarketType,
binance: &Arc<Binance>,
) -> Result<Arc<BinanceWs>>
pub async fn get_private_connection( &self, market_type: MarketType, binance: &Arc<Binance>, ) -> Result<Arc<BinanceWs>>
Sourcepub async fn active_shards_count(&self) -> usize
pub async fn active_shards_count(&self) -> usize
Returns the number of active public shards across all market types.
Sourcepub async fn active_shards_count_for(&self, market_type: MarketType) -> usize
pub async fn active_shards_count_for(&self, market_type: MarketType) -> usize
Returns the number of active public shards for a specific market type.
Sourcepub async fn disconnect_all(&self) -> Result<()>
pub async fn disconnect_all(&self) -> Result<()>
Disconnects all active connections across all market types.
Sourcepub async fn disconnect_market(&self, market_type: MarketType) -> Result<()>
pub async fn disconnect_market(&self, market_type: MarketType) -> Result<()>
Disconnects all connections for a specific market type.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Checks if any connection is active (non-blocking).
Sourcepub fn is_connected_for(&self, market_type: MarketType) -> bool
pub fn is_connected_for(&self, market_type: MarketType) -> bool
Checks if a connection is active for a specific market type (non-blocking).
Sourcepub fn get_all_subscriptions(&self) -> Vec<String>
pub fn get_all_subscriptions(&self) -> Vec<String>
Returns a list of all active subscriptions across all connections.
Sourcepub fn get_subscriptions_for(&self, market_type: MarketType) -> Vec<String>
pub fn get_subscriptions_for(&self, market_type: MarketType) -> Vec<String>
Returns a list of active subscriptions for a specific market type.
Sourcepub fn urls(&self) -> &BinanceUrls
pub fn urls(&self) -> &BinanceUrls
Returns a reference to the URLs configuration.
Sourcepub fn is_sandbox(&self) -> bool
pub fn is_sandbox(&self) -> bool
Returns whether this manager is configured for sandbox/testnet.