Skip to main content

barter_data/exchange/binance/spot/
mod.rs

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