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