Skip to main content

nautilus_kraken/websocket/spot_v2/
enums.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 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//! Enumerations for Kraken WebSocket v2 API.
17
18use nautilus_model::enums::{LiquiditySide, OrderStatus};
19use serde::{Deserialize, Serialize};
20use strum::{AsRefStr, Display, EnumString, FromRepr};
21
22#[derive(
23    Clone,
24    Copy,
25    Debug,
26    Display,
27    AsRefStr,
28    EnumString,
29    FromRepr,
30    PartialEq,
31    Eq,
32    Hash,
33    Serialize,
34    Deserialize,
35)]
36#[cfg_attr(
37    feature = "python",
38    pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.kraken", eq, eq_int)
39)]
40#[serde(rename_all = "lowercase")]
41#[strum(ascii_case_insensitive, serialize_all = "lowercase")]
42pub enum KrakenWsMethod {
43    Subscribe,
44    Unsubscribe,
45    Ping,
46    Pong,
47}
48
49#[derive(
50    Clone,
51    Copy,
52    Debug,
53    Display,
54    AsRefStr,
55    EnumString,
56    FromRepr,
57    PartialEq,
58    Eq,
59    Hash,
60    Serialize,
61    Deserialize,
62)]
63#[cfg_attr(
64    feature = "python",
65    pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.kraken", eq, eq_int)
66)]
67#[serde(rename_all = "lowercase")]
68#[strum(ascii_case_insensitive, serialize_all = "lowercase")]
69pub enum KrakenWsChannel {
70    Ticker,
71    #[serde(rename = "trade")]
72    #[strum(serialize = "trade")]
73    Trade,
74    #[serde(rename = "book")]
75    #[strum(serialize = "book")]
76    Book,
77    #[serde(rename = "ohlc")]
78    #[strum(serialize = "ohlc")]
79    Ohlc,
80    #[serde(rename = "spread")]
81    #[strum(serialize = "spread")]
82    Spread,
83    // Private channels
84    #[serde(rename = "executions")]
85    #[strum(serialize = "executions")]
86    Executions,
87    #[serde(rename = "balances")]
88    #[strum(serialize = "balances")]
89    Balances,
90}
91
92#[derive(
93    Clone,
94    Copy,
95    Debug,
96    Display,
97    AsRefStr,
98    EnumString,
99    FromRepr,
100    PartialEq,
101    Eq,
102    Hash,
103    Serialize,
104    Deserialize,
105)]
106#[cfg_attr(
107    feature = "python",
108    pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.kraken", eq, eq_int)
109)]
110#[serde(rename_all = "lowercase")]
111#[strum(ascii_case_insensitive, serialize_all = "lowercase")]
112pub enum KrakenWsMessageType {
113    Heartbeat,
114    Status,
115    Subscribe,
116    Unsubscribe,
117    Update,
118    Snapshot,
119    Error,
120}
121
122/// Execution type from the Kraken executions channel.
123#[derive(
124    Clone,
125    Copy,
126    Debug,
127    Display,
128    AsRefStr,
129    EnumString,
130    FromRepr,
131    PartialEq,
132    Eq,
133    Hash,
134    Serialize,
135    Deserialize,
136)]
137#[serde(rename_all = "snake_case")]
138#[strum(ascii_case_insensitive, serialize_all = "snake_case")]
139pub enum KrakenExecType {
140    /// Order is pending submission to the exchange.
141    #[serde(rename = "pending_new")]
142    #[strum(serialize = "pending_new")]
143    PendingNew,
144    /// Order has been accepted by the exchange.
145    New,
146    /// Order has been partially or fully filled.
147    Trade,
148    /// Order has been completely filled.
149    Filled,
150    /// Iceberg order refill.
151    #[serde(rename = "iceberg_refill")]
152    #[strum(serialize = "iceberg_refill")]
153    IcebergRefill,
154    /// Order has been canceled.
155    Canceled,
156    /// Order has expired.
157    Expired,
158    /// Order has been amended (user-initiated modification).
159    Amended,
160    /// Order has been restated (engine-initiated adjustment).
161    Restated,
162    /// Order status update without state change.
163    Status,
164}
165
166/// Order status from the Kraken WebSocket v2 executions channel.
167#[derive(
168    Clone,
169    Copy,
170    Debug,
171    Display,
172    AsRefStr,
173    EnumString,
174    FromRepr,
175    PartialEq,
176    Eq,
177    Hash,
178    Serialize,
179    Deserialize,
180)]
181#[serde(rename_all = "snake_case")]
182#[strum(ascii_case_insensitive, serialize_all = "snake_case")]
183pub enum KrakenWsOrderStatus {
184    /// Order is pending submission.
185    #[serde(rename = "pending_new")]
186    #[strum(serialize = "pending_new")]
187    PendingNew,
188    /// Order has been accepted.
189    New,
190    /// Order has been partially filled.
191    #[serde(rename = "partially_filled")]
192    #[strum(serialize = "partially_filled")]
193    PartiallyFilled,
194    /// Order has been completely filled.
195    Filled,
196    /// Order has been canceled.
197    Canceled,
198    /// Order has expired.
199    Expired,
200    /// Conditional order has been triggered.
201    Triggered,
202}
203
204/// Liquidity indicator from trade executions.
205#[derive(
206    Clone,
207    Copy,
208    Debug,
209    Display,
210    AsRefStr,
211    EnumString,
212    FromRepr,
213    PartialEq,
214    Eq,
215    Hash,
216    Serialize,
217    Deserialize,
218)]
219#[serde(rename_all = "lowercase")]
220#[strum(ascii_case_insensitive, serialize_all = "lowercase")]
221pub enum KrakenLiquidityInd {
222    /// Maker (limit order that added liquidity).
223    #[serde(rename = "m")]
224    #[strum(serialize = "m")]
225    Maker,
226    /// Taker (order that removed liquidity).
227    #[serde(rename = "t")]
228    #[strum(serialize = "t")]
229    Taker,
230}
231
232impl From<KrakenWsOrderStatus> for OrderStatus {
233    fn from(value: KrakenWsOrderStatus) -> Self {
234        match value {
235            KrakenWsOrderStatus::PendingNew => Self::Submitted,
236            KrakenWsOrderStatus::New => Self::Accepted,
237            KrakenWsOrderStatus::PartiallyFilled => Self::PartiallyFilled,
238            KrakenWsOrderStatus::Filled => Self::Filled,
239            KrakenWsOrderStatus::Canceled => Self::Canceled,
240            KrakenWsOrderStatus::Expired => Self::Expired,
241            KrakenWsOrderStatus::Triggered => Self::Triggered,
242        }
243    }
244}
245
246impl From<KrakenLiquidityInd> for LiquiditySide {
247    fn from(value: KrakenLiquidityInd) -> Self {
248        match value {
249            KrakenLiquidityInd::Maker => Self::Maker,
250            KrakenLiquidityInd::Taker => Self::Taker,
251        }
252    }
253}