barter_data/exchange/binance/channel.rs
1use super::{Binance, futures::BinanceFuturesUsd};
2use crate::{
3 Identifier,
4 subscription::{
5 Subscription,
6 book::{OrderBooksL1, OrderBooksL2},
7 liquidation::Liquidations,
8 trade::PublicTrades,
9 },
10};
11use serde::Serialize;
12
13/// Type that defines how to translate a Barter [`Subscription`] into a [`Binance`]
14/// channel to be subscribed to.
15///
16/// See docs: <https://binance-docs.github.io/apidocs/spot/en/#websocket-market-streams>
17/// See docs: <https://binance-docs.github.io/apidocs/futures/en/#websocket-market-streams>
18#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize)]
19pub struct BinanceChannel(pub &'static str);
20
21impl BinanceChannel {
22 /// [`Binance`] real-time trades channel name.
23 ///
24 /// See docs: <https://binance-docs.github.io/apidocs/spot/en/#trade-streams>
25 ///
26 /// Note:
27 /// For [`BinanceFuturesUsd`] this real-time
28 /// stream is undocumented.
29 ///
30 /// See discord: <https://discord.com/channels/910237311332151317/923160222711812126/975712874582388757>
31 pub const TRADES: Self = Self("@trade");
32
33 /// [`Binance`] real-time OrderBook Level1 (top of books) channel name.
34 ///
35 /// See docs:<https://binance-docs.github.io/apidocs/spot/en/#individual-symbol-book-ticker-streams>
36 /// See docs:<https://binance-docs.github.io/apidocs/futures/en/#individual-symbol-book-ticker-streams>
37 pub const ORDER_BOOK_L1: Self = Self("@bookTicker");
38
39 /// [`Binance`] OrderBook Level2 channel name (100ms delta updates).
40 ///
41 /// See docs: <https://binance-docs.github.io/apidocs/spot/en/#diff-depth-stream>
42 /// See docs: <https://binance-docs.github.io/apidocs/futures/en/#diff-book-depth-streams>
43 pub const ORDER_BOOK_L2: Self = Self("@depth@100ms");
44
45 /// [`BinanceFuturesUsd`] liquidation orders channel name.
46 ///
47 /// See docs: <https://binance-docs.github.io/apidocs/futures/en/#liquidation-order-streams>
48 pub const LIQUIDATIONS: Self = Self("@forceOrder");
49}
50
51impl<Server, Instrument> Identifier<BinanceChannel>
52 for Subscription<Binance<Server>, Instrument, PublicTrades>
53{
54 fn id(&self) -> BinanceChannel {
55 BinanceChannel::TRADES
56 }
57}
58
59impl<Server, Instrument> Identifier<BinanceChannel>
60 for Subscription<Binance<Server>, Instrument, OrderBooksL1>
61{
62 fn id(&self) -> BinanceChannel {
63 BinanceChannel::ORDER_BOOK_L1
64 }
65}
66
67impl<Server, Instrument> Identifier<BinanceChannel>
68 for Subscription<Binance<Server>, Instrument, OrderBooksL2>
69{
70 fn id(&self) -> BinanceChannel {
71 BinanceChannel::ORDER_BOOK_L2
72 }
73}
74
75impl<Instrument> Identifier<BinanceChannel>
76 for Subscription<BinanceFuturesUsd, Instrument, Liquidations>
77{
78 fn id(&self) -> BinanceChannel {
79 BinanceChannel::LIQUIDATIONS
80 }
81}
82
83impl AsRef<str> for BinanceChannel {
84 fn as_ref(&self) -> &str {
85 self.0
86 }
87}