nautilus_dydx/websocket/enums.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3// https://nautechsystems.io
4//
5// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6// You may not use this file except in compliance with the License.
7// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16//! Enums for dYdX WebSocket operations and channels.
17
18use serde::{Deserialize, Serialize};
19use strum::{AsRefStr, Display, EnumString, FromRepr};
20
21/// WebSocket operation types for dYdX.
22#[derive(
23 Clone,
24 Copy,
25 Debug,
26 PartialEq,
27 Eq,
28 Hash,
29 Display,
30 AsRefStr,
31 EnumString,
32 FromRepr,
33 Serialize,
34 Deserialize,
35)]
36#[serde(rename_all = "snake_case")]
37#[strum(serialize_all = "snake_case")]
38pub enum DydxWsOperation {
39 /// Subscribe to a channel.
40 Subscribe,
41 /// Unsubscribe from a channel.
42 Unsubscribe,
43 /// Ping keepalive message.
44 Ping,
45 /// Pong response to ping.
46 Pong,
47}
48
49/// dYdX WebSocket channel identifiers.
50///
51/// # References
52///
53/// <https://docs.dydx.trade/developers/indexer/websockets>
54#[derive(
55 Clone,
56 Copy,
57 Debug,
58 PartialEq,
59 Eq,
60 Hash,
61 Display,
62 AsRefStr,
63 EnumString,
64 FromRepr,
65 Serialize,
66 Deserialize,
67)]
68#[serde(rename_all = "snake_case")]
69#[strum(serialize_all = "snake_case")]
70pub enum DydxWsChannel {
71 /// Market data for all markets.
72 #[serde(rename = "v4_markets")]
73 #[strum(serialize = "v4_markets")]
74 Markets,
75 /// Trade stream for specific market.
76 #[serde(rename = "v4_trades")]
77 #[strum(serialize = "v4_trades")]
78 Trades,
79 /// Order book snapshots and updates.
80 #[serde(rename = "v4_orderbook")]
81 #[strum(serialize = "v4_orderbook")]
82 Orderbook,
83 /// Candlestick/kline data.
84 #[serde(rename = "v4_candles")]
85 #[strum(serialize = "v4_candles")]
86 Candles,
87 /// Subaccount updates (orders, fills, positions).
88 #[serde(rename = "v4_subaccounts")]
89 #[strum(serialize = "v4_subaccounts")]
90 Subaccounts,
91 /// Block height updates from chain.
92 #[serde(rename = "v4_block_height")]
93 #[strum(serialize = "v4_block_height")]
94 BlockHeight,
95}
96
97impl DydxWsChannel {
98 /// Returns `true` if this is a private channel requiring authentication.
99 #[must_use]
100 pub const fn is_private(&self) -> bool {
101 matches!(self, Self::Subaccounts)
102 }
103
104 /// Returns `true` if this is a public channel.
105 #[must_use]
106 pub const fn is_public(&self) -> bool {
107 !self.is_private()
108 }
109}