hypercall_ws_protocol/
channel.rs1pub const UNKNOWN_CHANNEL_CODE: &str = "unknown_channel";
11
12pub const RETIRED_CHANNELS: &[&str] = &["competition", "competition_engagement"];
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
18pub enum WsChannel {
19 Orderbook,
20 Trades,
21 MarketUpdates,
22 OptionsChain,
23 IndexPrices,
24 IndicativeMarketData,
26 IndicativeMarketDataV2,
30 OrderUpdates,
31 Fills,
32 Portfolio,
33 Liquidation,
34 Rfq,
35 #[cfg(feature = "rfq-v2")]
38 RfqV2,
39 ExperimentalOrderUpdates,
40 ExperimentalComboTrades,
41 ExperimentalComboFills,
42}
43
44impl WsChannel {
45 #[cfg(not(feature = "rfq-v2"))]
46 pub const ALL: [Self; 15] = [
47 Self::Orderbook,
48 Self::Trades,
49 Self::MarketUpdates,
50 Self::OptionsChain,
51 Self::IndexPrices,
52 Self::IndicativeMarketData,
53 Self::IndicativeMarketDataV2,
54 Self::OrderUpdates,
55 Self::Fills,
56 Self::Portfolio,
57 Self::Liquidation,
58 Self::Rfq,
59 Self::ExperimentalOrderUpdates,
60 Self::ExperimentalComboTrades,
61 Self::ExperimentalComboFills,
62 ];
63
64 #[cfg(feature = "rfq-v2")]
65 pub const ALL: [Self; 16] = [
66 Self::Orderbook,
67 Self::Trades,
68 Self::MarketUpdates,
69 Self::OptionsChain,
70 Self::IndexPrices,
71 Self::IndicativeMarketData,
72 Self::IndicativeMarketDataV2,
73 Self::OrderUpdates,
74 Self::Fills,
75 Self::Portfolio,
76 Self::Liquidation,
77 Self::Rfq,
78 Self::RfqV2,
79 Self::ExperimentalOrderUpdates,
80 Self::ExperimentalComboTrades,
81 Self::ExperimentalComboFills,
82 ];
83
84 pub const fn as_str(self) -> &'static str {
86 match self {
87 Self::Orderbook => "orderbook",
88 Self::Trades => "trades",
89 Self::MarketUpdates => "market_updates",
90 Self::OptionsChain => "options_chain",
91 Self::IndexPrices => "index_prices",
92 Self::IndicativeMarketData => "indicative_market_data",
93 Self::IndicativeMarketDataV2 => "indicative_market_data_v2",
94 Self::OrderUpdates => "order_updates",
95 Self::Fills => "fills",
96 Self::Portfolio => "portfolio",
97 Self::Liquidation => "liquidation",
98 Self::Rfq => "rfq",
99 #[cfg(feature = "rfq-v2")]
100 Self::RfqV2 => "rfq_v2",
101 Self::ExperimentalOrderUpdates => "experimental_order_updates",
102 Self::ExperimentalComboTrades => "experimental_combo_trades",
103 Self::ExperimentalComboFills => "experimental_combo_fills",
104 }
105 }
106
107 pub fn parse(name: &str) -> Option<Self> {
110 Self::ALL
111 .into_iter()
112 .find(|channel| channel.as_str() == name)
113 }
114
115 pub fn unknown_channel_message(name: &str) -> String {
117 format!("Unknown channel '{name}'")
118 }
119}
120
121impl std::fmt::Display for WsChannel {
122 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
123 formatter.write_str(self.as_str())
124 }
125}
126
127#[cfg(test)]
128#[path = "channel_test.rs"]
129mod tests;