barter_data/exchange/binance/spot/
mod.rs

1use super::{Binance, ExchangeServer};
2use crate::{
3    ExchangeWsStream,
4    exchange::{
5        StreamSelector,
6        binance::spot::l2::{
7            BinanceSpotOrderBooksL2SnapshotFetcher, BinanceSpotOrderBooksL2Transformer,
8        },
9    },
10    instrument::InstrumentData,
11    subscription::book::OrderBooksL2,
12};
13use barter_instrument::exchange::ExchangeId;
14use std::fmt::{Display, Formatter};
15
16/// Level 2 OrderBook types.
17pub mod l2;
18
19/// [`BinanceSpot`] WebSocket server base url.
20///
21/// See docs: <https://binance-docs.github.io/apidocs/spot/en/#websocket-market-streams>
22pub const WEBSOCKET_BASE_URL_BINANCE_SPOT: &str = "wss://stream.binance.com:9443/ws";
23
24/// [`Binance`] spot exchange.
25pub type BinanceSpot = Binance<BinanceServerSpot>;
26
27/// [`Binance`] spot [`ExchangeServer`].
28#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
29pub struct BinanceServerSpot;
30
31impl ExchangeServer for BinanceServerSpot {
32    const ID: ExchangeId = ExchangeId::BinanceSpot;
33
34    fn websocket_url() -> &'static str {
35        WEBSOCKET_BASE_URL_BINANCE_SPOT
36    }
37}
38
39impl<Instrument> StreamSelector<Instrument, OrderBooksL2> for BinanceSpot
40where
41    Instrument: InstrumentData,
42{
43    type SnapFetcher = BinanceSpotOrderBooksL2SnapshotFetcher;
44    type Stream = ExchangeWsStream<BinanceSpotOrderBooksL2Transformer<Instrument::Key>>;
45}
46
47impl Display for BinanceSpot {
48    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
49        write!(f, "BinanceSpot")
50    }
51}