pub struct BinanceSpotWebSocketClient { /* private fields */ }Expand description
Binance Spot WebSocket client for SBE market data streams.
Manages a pool of up to 20 connections, each supporting up to 1024 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 BinanceSpotWebSocketClient
impl BinanceSpotWebSocketClient
Sourcepub fn new(
url: Option<String>,
api_key: Option<String>,
api_secret: Option<String>,
heartbeat: Option<u64>,
transport_backend: TransportBackend,
) -> Result<Self>
pub fn new( url: Option<String>, api_key: Option<String>, api_secret: Option<String>, heartbeat: Option<u64>, transport_backend: TransportBackend, ) -> Result<Self>
Creates a new BinanceSpotWebSocketClient instance.
§Errors
Returns an error if credential creation fails.
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 1024-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 = BinanceSpotWsMessage> + 'static
pub fn stream(&self) -> impl Stream<Item = BinanceSpotWsMessage> + '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 symbol.
Trait Implementations§
Source§impl Clone for BinanceSpotWebSocketClient
impl Clone for BinanceSpotWebSocketClient
Source§fn clone(&self) -> BinanceSpotWebSocketClient
fn clone(&self) -> BinanceSpotWebSocketClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BinanceSpotWebSocketClient
impl Debug for BinanceSpotWebSocketClient
Auto Trait Implementations§
impl Freeze for BinanceSpotWebSocketClient
impl RefUnwindSafe for BinanceSpotWebSocketClient
impl Send for BinanceSpotWebSocketClient
impl Sync for BinanceSpotWebSocketClient
impl Unpin for BinanceSpotWebSocketClient
impl UnsafeUnpin for BinanceSpotWebSocketClient
impl UnwindSafe for BinanceSpotWebSocketClient
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