barter_data/exchange/bybit/
channel.rs

1use crate::{
2    Identifier,
3    exchange::bybit::Bybit,
4    subscription::{
5        Subscription,
6        book::{OrderBooksL1, OrderBooksL2},
7        trade::PublicTrades,
8    },
9};
10use serde::Serialize;
11
12/// Type that defines how to translate a Barter [`Subscription`] into a [`Bybit`]
13/// channel to be subscribed to.
14///
15/// See docs: <https://bybit-exchange.github.io/docs/v5/ws/connect>
16#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize)]
17pub struct BybitChannel(pub &'static str);
18
19impl BybitChannel {
20    /// [`Bybit`] real-time trades channel name.
21    ///
22    /// See docs: <https://bybit-exchange.github.io/docs/v5/websocket/public/trade>
23    pub const TRADES: Self = Self("publicTrade");
24
25    /// [`Bybit`] real-time OrderBook Level1 (top of books) channel name.
26    ///
27    /// See docs: <https://bybit-exchange.github.io/docs/v5/websocket/public/orderbook>
28    pub const ORDER_BOOK_L1: Self = Self("orderbook.1");
29
30    /// [`Bybit`] OrderBook Level2 channel name (20ms delta updates).
31    ///
32    /// See docs: <https://bybit-exchange.github.io/docs/v5/websocket/public/orderbook>
33    pub const ORDER_BOOK_L2: Self = Self("orderbook.50");
34}
35
36impl<Server, Instrument> Identifier<BybitChannel>
37    for Subscription<Bybit<Server>, Instrument, PublicTrades>
38{
39    fn id(&self) -> BybitChannel {
40        BybitChannel::TRADES
41    }
42}
43
44impl<Server, Instrument> Identifier<BybitChannel>
45    for Subscription<Bybit<Server>, Instrument, OrderBooksL1>
46{
47    fn id(&self) -> BybitChannel {
48        BybitChannel::ORDER_BOOK_L1
49    }
50}
51
52impl<Server, Instrument> Identifier<BybitChannel>
53    for Subscription<Bybit<Server>, Instrument, OrderBooksL2>
54{
55    fn id(&self) -> BybitChannel {
56        BybitChannel::ORDER_BOOK_L2
57    }
58}
59
60impl AsRef<str> for BybitChannel {
61    fn as_ref(&self) -> &str {
62        self.0
63    }
64}