xapi_binance/clients/spot/
stream.rs

1use crate::{clients::spot::BnSpot, data::book_ticker::BnBookTickerStream};
2use tokio::sync::mpsc;
3use xapi_shared::{data::crypto_symbol::CryptoSymbol, ws::error::SharedWsError};
4
5impl BnSpot {
6    /// Pushes any update to the best bid or ask's price or quantity in real-time for a specified symbol. Multiple <symbol>@bookTicker streams can be subscribed to over one connection.
7    ///
8    /// <https://developers.binance.com/docs/binance-spot-api-docs/web-socket-streams#individual-symbol-book-ticker-streams>
9    pub async fn subscribe_book_ticker(
10        &self,
11        symbol: &CryptoSymbol,
12    ) -> Result<mpsc::Receiver<Result<BnBookTickerStream, SharedWsError>>, SharedWsError> {
13        self.executor
14            .subscribe_stream(format!("{}@bookTicker", symbol.as_str().to_lowercase()))
15            .await
16    }
17}