nautilus_coinbase_intx/common/
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
16use nautilus_model::enums::{AggressorSide, OrderSide, OrderType, TimeInForce};
17use serde::{Deserialize, Serialize};
18use strum::{AsRefStr, Display, EnumIter, EnumString};
19
20/// Represents the type of book action.
21#[derive(
22    Copy,
23    Clone,
24    Debug,
25    Display,
26    PartialEq,
27    Eq,
28    AsRefStr,
29    EnumIter,
30    EnumString,
31    Serialize,
32    Deserialize,
33)]
34#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
35pub enum CoinbaseIntxFeeTierType {
36    Regular,
37    LiquidityProgram,
38}
39
40/// Represents the type of book action.
41#[derive(
42    Copy,
43    Clone,
44    Debug,
45    Display,
46    PartialEq,
47    Eq,
48    AsRefStr,
49    EnumIter,
50    EnumString,
51    Serialize,
52    Deserialize,
53)]
54#[serde(rename_all = "lowercase")]
55pub enum CoinbaseIntxBookAction {
56    /// Incremental update.
57    Update,
58    /// Full snapshot.
59    Snapshot,
60}
61
62/// Represents the possible states of an order throughout its lifecycle.
63#[derive(
64    Copy,
65    Clone,
66    Debug,
67    Display,
68    PartialEq,
69    Eq,
70    AsRefStr,
71    EnumIter,
72    EnumString,
73    Serialize,
74    Deserialize,
75)]
76pub enum CoinbaseIntxCandleConfirm {
77    /// K-line is "uncompleted".
78    #[serde(rename = "0")]
79    Partial,
80    /// K-line is completed.
81    #[serde(rename = "1")]
82    Closed,
83}
84
85/// Represents the side of an order or trade (Buy/Sell).
86#[derive(
87    Copy,
88    Clone,
89    Debug,
90    Display,
91    PartialEq,
92    Eq,
93    AsRefStr,
94    EnumIter,
95    EnumString,
96    Serialize,
97    Deserialize,
98)]
99#[serde(rename_all = "UPPERCASE")]
100pub enum CoinbaseIntxSide {
101    /// Buy side of a trade or order.
102    Buy,
103    /// Sell side of a trade or order.
104    Sell,
105}
106
107impl From<OrderSide> for CoinbaseIntxSide {
108    fn from(value: OrderSide) -> Self {
109        match value {
110            OrderSide::Buy => Self::Buy,
111            OrderSide::Sell => Self::Sell,
112            _ => panic!("Invalid `OrderSide`"),
113        }
114    }
115}
116
117impl From<AggressorSide> for CoinbaseIntxSide {
118    fn from(value: AggressorSide) -> Self {
119        match value {
120            AggressorSide::Buyer => Self::Buy,
121            AggressorSide::Seller => Self::Sell,
122            _ => panic!("Invalid `AggressorSide`"),
123        }
124    }
125}
126
127impl From<CoinbaseIntxSide> for OrderSide {
128    fn from(value: CoinbaseIntxSide) -> Self {
129        match value {
130            CoinbaseIntxSide::Buy => Self::Buy,
131            CoinbaseIntxSide::Sell => Self::Sell,
132        }
133    }
134}
135
136impl From<CoinbaseIntxSide> for AggressorSide {
137    fn from(value: CoinbaseIntxSide) -> Self {
138        match value {
139            CoinbaseIntxSide::Buy => Self::Buyer,
140            CoinbaseIntxSide::Sell => Self::Seller,
141        }
142    }
143}
144
145/// Represents an order type.
146#[derive(
147    Copy,
148    Clone,
149    Debug,
150    Display,
151    PartialEq,
152    Eq,
153    AsRefStr,
154    EnumIter,
155    EnumString,
156    Serialize,
157    Deserialize,
158)]
159#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
160pub enum CoinbaseIntxOrderType {
161    Limit,
162    Market,
163    StopLimit,
164    Stop,
165    TakeProfitStopLoss,
166}
167
168impl From<CoinbaseIntxOrderType> for OrderType {
169    fn from(value: CoinbaseIntxOrderType) -> Self {
170        match value {
171            CoinbaseIntxOrderType::Limit => Self::Limit,
172            CoinbaseIntxOrderType::Market => Self::Market,
173            CoinbaseIntxOrderType::StopLimit => Self::StopLimit,
174            CoinbaseIntxOrderType::Stop => Self::StopMarket,
175            CoinbaseIntxOrderType::TakeProfitStopLoss => Self::MarketIfTouched,
176        }
177    }
178}
179
180impl From<OrderType> for CoinbaseIntxOrderType {
181    fn from(value: OrderType) -> Self {
182        match value {
183            OrderType::Limit => Self::Limit,
184            OrderType::Market => Self::Market,
185            OrderType::StopLimit => Self::StopLimit,
186            OrderType::StopMarket => Self::Stop,
187            OrderType::MarketIfTouched => Self::TakeProfitStopLoss,
188            _ => panic!("Invalid `OrderType` cannot be represented on Coinbase International"),
189        }
190    }
191}
192
193/// Represents an overall order status.
194#[derive(
195    Copy,
196    Clone,
197    Debug,
198    Display,
199    PartialEq,
200    Eq,
201    AsRefStr,
202    EnumIter,
203    EnumString,
204    Serialize,
205    Deserialize,
206)]
207#[serde(rename_all = "UPPERCASE")]
208pub enum CoinbaseIntxOrderStatus {
209    Working,
210    Done,
211}
212
213/// Represents an order time in force.
214#[derive(
215    Copy,
216    Clone,
217    Debug,
218    Default,
219    Display,
220    PartialEq,
221    Eq,
222    AsRefStr,
223    EnumIter,
224    EnumString,
225    Serialize,
226    Deserialize,
227)]
228#[serde(rename_all = "UPPERCASE")]
229pub enum CoinbaseIntxTimeInForce {
230    #[default]
231    Gtc, // Good Till Cancel
232    Ioc, // Immediate or Cancel
233    Gtt, // Good Till Time
234    Fok, // Fill or Kill
235}
236
237impl From<TimeInForce> for CoinbaseIntxTimeInForce {
238    fn from(time_in_force: TimeInForce) -> Self {
239        match time_in_force {
240            TimeInForce::Gtc => Self::Gtc,
241            TimeInForce::Ioc => Self::Ioc,
242            TimeInForce::Fok => Self::Fok,
243            TimeInForce::Gtd => Self::Gtt,
244            _ => panic!("Invalid `TimeInForce` cannot be represented on Coinbase International"),
245        }
246    }
247}
248
249impl From<CoinbaseIntxTimeInForce> for TimeInForce {
250    fn from(coinbase_tif: CoinbaseIntxTimeInForce) -> Self {
251        match coinbase_tif {
252            CoinbaseIntxTimeInForce::Gtc => Self::Gtc,
253            CoinbaseIntxTimeInForce::Ioc => Self::Ioc,
254            CoinbaseIntxTimeInForce::Fok => Self::Fok,
255            CoinbaseIntxTimeInForce::Gtt => Self::Gtd,
256        }
257    }
258}
259
260/// Represents a self trade protection (STP) mode.
261#[derive(
262    Copy,
263    Clone,
264    Debug,
265    Display,
266    PartialEq,
267    Eq,
268    AsRefStr,
269    EnumIter,
270    EnumString,
271    Serialize,
272    Deserialize,
273)]
274#[serde(rename_all = "UPPERCASE")]
275pub enum CoinbaseIntxSTPMode {
276    None,
277    Aggressing,
278    Resting,
279    Both,
280    DecrementAndCancel,
281}
282
283/// Represents an order event type.
284#[derive(
285    Copy,
286    Clone,
287    Debug,
288    Display,
289    PartialEq,
290    Eq,
291    AsRefStr,
292    EnumIter,
293    EnumString,
294    Serialize,
295    Deserialize,
296)]
297#[serde(rename_all = "UPPERCASE")]
298pub enum CoinbaseIntxOrderEventType {
299    New,
300    Trade,
301    Canceled,
302    Replaced,
303    PendingCancel,
304    Rejected,
305    PendingNew,
306    Expired,
307    PendingReplace,
308    StopTriggered,
309}
310
311/// Represents an algo strategy.
312#[derive(
313    Copy,
314    Clone,
315    Debug,
316    Display,
317    PartialEq,
318    Eq,
319    AsRefStr,
320    EnumIter,
321    EnumString,
322    Serialize,
323    Deserialize,
324)]
325#[serde(rename_all = "UPPERCASE")]
326pub enum CoinbaseIntxAlgoStrategy {
327    Twap,
328}
329
330/// Represents the type of execution that generated a trade.
331#[derive(
332    Copy,
333    Clone,
334    Debug,
335    Display,
336    PartialEq,
337    Eq,
338    AsRefStr,
339    EnumIter,
340    EnumString,
341    Serialize,
342    Deserialize,
343)]
344pub enum CoinbaseIntxExecType {
345    #[serde(rename = "T")]
346    Taker,
347    #[serde(rename = "M")]
348    Maker,
349    #[serde(rename = "")]
350    None,
351}
352
353/// Represents instrument types on Coinbase International.
354#[derive(
355    Copy,
356    Clone,
357    Debug,
358    Display,
359    PartialEq,
360    Eq,
361    AsRefStr,
362    EnumIter,
363    EnumString,
364    Serialize,
365    Deserialize,
366)]
367#[serde(rename_all = "UPPERCASE")]
368pub enum CoinbaseIntxInstrumentType {
369    /// Spot products.
370    Spot,
371    /// Perpetual products.
372    Perp,
373    /// Index products.
374    Index,
375}
376
377/// Represents an asset status on Coinbase International.
378#[derive(
379    Copy,
380    Clone,
381    Debug,
382    Display,
383    PartialEq,
384    Eq,
385    AsRefStr,
386    EnumIter,
387    EnumString,
388    Serialize,
389    Deserialize,
390)]
391#[serde(rename_all = "UPPERCASE")]
392pub enum CoinbaseIntxAssetStatus {
393    /// Asset is actively trading.
394    Active,
395}
396
397/// Represents an instrument status on Coinbase International.
398#[derive(
399    Copy,
400    Clone,
401    Debug,
402    Display,
403    PartialEq,
404    Eq,
405    AsRefStr,
406    EnumIter,
407    EnumString,
408    Serialize,
409    Deserialize,
410)]
411#[serde(rename_all = "UPPERCASE")]
412pub enum CoinbaseIntxTradingState {
413    /// Instrument is actively trading.
414    Trading,
415    /// Instrument trading is paused.
416    Paused,
417    /// Instrument trading is halted.
418    Halt,
419    /// Instrument has been delisted.
420    Delisted,
421    /// TBD.
422    External,
423}