pub struct BinanceFuturesWebSocketClient { /* private fields */ }Expand description
Binance Futures WebSocket client for JSON market data streams.
Manages a pool of up to 20 connections, each supporting up to 200 streams. New connections are created automatically when subscribing exceeds the current connection’s stream limit. All connections feed into a single output stream, transparent to the data client.
Implementations§
Source§impl BinanceFuturesWebSocketClient
impl BinanceFuturesWebSocketClient
Sourcepub fn new(
product_type: BinanceProductType,
environment: BinanceEnvironment,
api_key: Option<String>,
api_secret: Option<String>,
url_override: Option<String>,
heartbeat: Option<u64>,
transport_backend: TransportBackend,
) -> Result<Self>
pub fn new( product_type: BinanceProductType, environment: BinanceEnvironment, api_key: Option<String>, api_secret: Option<String>, url_override: Option<String>, heartbeat: Option<u64>, transport_backend: TransportBackend, ) -> Result<Self>
Creates a new BinanceFuturesWebSocketClient instance.
§Errors
Returns an error if:
product_typeis not a futures type (UsdM or CoinM).- Credential creation fails.
Sourcepub const fn product_type(&self) -> BinanceProductType
pub const fn product_type(&self) -> BinanceProductType
Returns the product type (UsdM or CoinM).
Sourcepub fn subscription_count(&self) -> usize
pub fn subscription_count(&self) -> usize
Returns the total number of confirmed subscriptions across all connections.
Sourcepub async fn connect(&mut self) -> BinanceWsResult<()>
pub async fn connect(&mut self) -> BinanceWsResult<()>
Sourcepub async fn close(&mut self) -> BinanceWsResult<()>
pub async fn close(&mut self) -> BinanceWsResult<()>
Sourcepub async fn subscribe(&self, streams: Vec<String>) -> BinanceWsResult<()>
pub async fn subscribe(&self, streams: Vec<String>) -> BinanceWsResult<()>
Subscribes to the specified streams.
Streams are distributed across pool connections. New connections are created automatically when existing ones reach the 200-stream limit, up to a maximum of 20 connections.
§Errors
Returns an error if the pool is exhausted or command delivery fails.
Sourcepub async fn unsubscribe(&self, streams: Vec<String>) -> BinanceWsResult<()>
pub async fn unsubscribe(&self, streams: Vec<String>) -> BinanceWsResult<()>
Sourcepub fn stream(
&self,
) -> impl Stream<Item = BinanceFuturesWsStreamsMessage> + 'static
pub fn stream( &self, ) -> impl Stream<Item = BinanceFuturesWsStreamsMessage> + 'static
Returns a stream of messages from all WebSocket connections.
This method can only be called once per connection lifecycle. Subsequent calls return an empty stream.
§Panics
Panics if the internal output receiver mutex is poisoned.
Sourcepub fn cache_instruments(&self, instruments: &[InstrumentAny])
pub fn cache_instruments(&self, instruments: &[InstrumentAny])
Bulk initialize the instrument cache.
Sourcepub fn cache_instrument(&self, instrument: InstrumentAny)
pub fn cache_instrument(&self, instrument: InstrumentAny)
Update a single instrument in the cache.
Sourcepub fn instruments_cache(&self) -> Arc<AtomicMap<Ustr, InstrumentAny>> ⓘ
pub fn instruments_cache(&self) -> Arc<AtomicMap<Ustr, InstrumentAny>> ⓘ
Returns a shared reference to the instruments cache.
Sourcepub fn get_instrument(&self, symbol: &str) -> Option<InstrumentAny>
pub fn get_instrument(&self, symbol: &str) -> Option<InstrumentAny>
Returns an instrument from the cache by raw symbol.
Trait Implementations§
Source§impl Clone for BinanceFuturesWebSocketClient
impl Clone for BinanceFuturesWebSocketClient
Source§fn clone(&self) -> BinanceFuturesWebSocketClient
fn clone(&self) -> BinanceFuturesWebSocketClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for BinanceFuturesWebSocketClient
impl RefUnwindSafe for BinanceFuturesWebSocketClient
impl Send for BinanceFuturesWebSocketClient
impl Sync for BinanceFuturesWebSocketClient
impl Unpin for BinanceFuturesWebSocketClient
impl UnsafeUnpin for BinanceFuturesWebSocketClient
impl UnwindSafe for BinanceFuturesWebSocketClient
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more