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    Clone, Debug, Display, PartialEq, Eq, AsRefStr, EnumIter, EnumString, Serialize, Deserialize,
23)]
24#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
25pub enum CoinbaseIntxFeeTierType {
26    Regular,
27    LiquidityProgram,
28}
29
30/// Represents the type of book action.
31#[derive(
32    Clone, Debug, Display, PartialEq, Eq, AsRefStr, EnumIter, EnumString, Serialize, Deserialize,
33)]
34#[serde(rename_all = "lowercase")]
35pub enum CoinbaseIntxBookAction {
36    /// Incremental update.
37    Update,
38    /// Full snapshot.
39    Snapshot,
40}
41
42/// Represents the possible states of an order throughout its lifecycle.
43#[derive(
44    Clone, Debug, Display, PartialEq, Eq, AsRefStr, EnumIter, EnumString, Serialize, Deserialize,
45)]
46pub enum CoinbaseIntxCandleConfirm {
47    /// K-line is "uncompleted".
48    #[serde(rename = "0")]
49    Partial,
50    /// K-line is completed.
51    #[serde(rename = "1")]
52    Closed,
53}
54
55/// Represents the side of an order or trade (Buy/Sell).
56#[derive(
57    Clone, Debug, Display, PartialEq, Eq, AsRefStr, EnumIter, EnumString, Serialize, Deserialize,
58)]
59#[serde(rename_all = "UPPERCASE")]
60pub enum CoinbaseIntxSide {
61    /// Buy side of a trade or order.
62    Buy,
63    /// Sell side of a trade or order.
64    Sell,
65}
66
67impl From<OrderSide> for CoinbaseIntxSide {
68    fn from(value: OrderSide) -> Self {
69        match value {
70            OrderSide::Buy => CoinbaseIntxSide::Buy,
71            OrderSide::Sell => CoinbaseIntxSide::Sell,
72            _ => panic!("Invalid `OrderSide`"),
73        }
74    }
75}
76
77impl From<AggressorSide> for CoinbaseIntxSide {
78    fn from(value: AggressorSide) -> Self {
79        match value {
80            AggressorSide::Buyer => CoinbaseIntxSide::Buy,
81            AggressorSide::Seller => CoinbaseIntxSide::Sell,
82            _ => panic!("Invalid `AggressorSide`"),
83        }
84    }
85}
86
87impl From<CoinbaseIntxSide> for OrderSide {
88    fn from(value: CoinbaseIntxSide) -> Self {
89        match value {
90            CoinbaseIntxSide::Buy => OrderSide::Buy,
91            CoinbaseIntxSide::Sell => OrderSide::Sell,
92        }
93    }
94}
95
96impl From<CoinbaseIntxSide> for AggressorSide {
97    fn from(value: CoinbaseIntxSide) -> Self {
98        match value {
99            CoinbaseIntxSide::Buy => AggressorSide::Buyer,
100            CoinbaseIntxSide::Sell => AggressorSide::Seller,
101        }
102    }
103}
104
105/// Represents an order type.
106#[derive(
107    Clone, Debug, Display, PartialEq, Eq, AsRefStr, EnumIter, EnumString, Serialize, Deserialize,
108)]
109#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
110pub enum CoinbaseIntxOrderType {
111    Limit,
112    Market,
113    StopLimit,
114    Stop,
115    TakeProfitStopLoss,
116}
117
118impl From<CoinbaseIntxOrderType> for OrderType {
119    fn from(value: CoinbaseIntxOrderType) -> Self {
120        match value {
121            CoinbaseIntxOrderType::Limit => OrderType::Limit,
122            CoinbaseIntxOrderType::Market => OrderType::Market,
123            CoinbaseIntxOrderType::StopLimit => OrderType::StopLimit,
124            CoinbaseIntxOrderType::Stop => OrderType::StopMarket,
125            CoinbaseIntxOrderType::TakeProfitStopLoss => OrderType::MarketIfTouched,
126        }
127    }
128}
129
130impl From<OrderType> for CoinbaseIntxOrderType {
131    fn from(value: OrderType) -> Self {
132        match value {
133            OrderType::Limit => CoinbaseIntxOrderType::Limit,
134            OrderType::Market => CoinbaseIntxOrderType::Market,
135            OrderType::StopLimit => CoinbaseIntxOrderType::StopLimit,
136            OrderType::StopMarket => CoinbaseIntxOrderType::Stop,
137            OrderType::MarketIfTouched => CoinbaseIntxOrderType::TakeProfitStopLoss,
138            _ => panic!("Invalid `OrderType` cannot be represented on Coinbase International"),
139        }
140    }
141}
142
143/// Represents an overall order status.
144#[derive(
145    Clone, Debug, Display, PartialEq, Eq, AsRefStr, EnumIter, EnumString, Serialize, Deserialize,
146)]
147#[serde(rename_all = "UPPERCASE")]
148pub enum CoinbaseIntxOrderStatus {
149    Working,
150    Done,
151}
152
153/// Represents an order time in force.
154#[derive(
155    Clone,
156    Debug,
157    Default,
158    Display,
159    PartialEq,
160    Eq,
161    AsRefStr,
162    EnumIter,
163    EnumString,
164    Serialize,
165    Deserialize,
166)]
167#[serde(rename_all = "UPPERCASE")]
168pub enum CoinbaseIntxTimeInForce {
169    #[default]
170    Gtc, // Good Till Cancel
171    Ioc, // Immediate or Cancel
172    Gtt, // Good Till Time
173    Fok, // Fill or Kill
174}
175
176impl From<TimeInForce> for CoinbaseIntxTimeInForce {
177    fn from(time_in_force: TimeInForce) -> Self {
178        match time_in_force {
179            TimeInForce::Gtc => CoinbaseIntxTimeInForce::Gtc,
180            TimeInForce::Ioc => CoinbaseIntxTimeInForce::Ioc,
181            TimeInForce::Fok => CoinbaseIntxTimeInForce::Fok,
182            TimeInForce::Gtd => CoinbaseIntxTimeInForce::Gtt,
183            _ => panic!("Invalid `TimeInForce` cannot be represented on Coinbase International"),
184        }
185    }
186}
187
188impl From<CoinbaseIntxTimeInForce> for TimeInForce {
189    fn from(coinbase_tif: CoinbaseIntxTimeInForce) -> Self {
190        match coinbase_tif {
191            CoinbaseIntxTimeInForce::Gtc => TimeInForce::Gtc,
192            CoinbaseIntxTimeInForce::Ioc => TimeInForce::Ioc,
193            CoinbaseIntxTimeInForce::Fok => TimeInForce::Fok,
194            CoinbaseIntxTimeInForce::Gtt => TimeInForce::Gtd,
195        }
196    }
197}
198
199/// Represents a self trade protection (STP) mode.
200#[derive(
201    Clone, Debug, Display, PartialEq, Eq, AsRefStr, EnumIter, EnumString, Serialize, Deserialize,
202)]
203#[serde(rename_all = "UPPERCASE")]
204pub enum CoinbaseIntxSTPMode {
205    None,
206    Aggressing,
207    Resting,
208    Both,
209    DecrementAndCancel,
210}
211
212/// Represents an order event type.
213#[derive(
214    Clone, Debug, Display, PartialEq, Eq, AsRefStr, EnumIter, EnumString, Serialize, Deserialize,
215)]
216#[serde(rename_all = "UPPERCASE")]
217pub enum CoinbaseIntxOrderEventType {
218    New,
219    Trade,
220    Canceled,
221    Replaced,
222    PendingCancel,
223    Rejected,
224    PendingNew,
225    Expired,
226    PendingReplace,
227    StopTriggered,
228}
229
230/// Represents an algo strategy.
231#[derive(
232    Clone, Debug, Display, PartialEq, Eq, AsRefStr, EnumIter, EnumString, Serialize, Deserialize,
233)]
234#[serde(rename_all = "UPPERCASE")]
235pub enum CoinbaseIntxAlgoStrategy {
236    Twap,
237}
238
239/// Represents the type of execution that generated a trade.
240#[derive(
241    Clone, Debug, Display, PartialEq, Eq, AsRefStr, EnumIter, EnumString, Serialize, Deserialize,
242)]
243pub enum CoinbaseIntxExecType {
244    #[serde(rename = "T")]
245    Taker,
246    #[serde(rename = "M")]
247    Maker,
248    #[serde(rename = "")]
249    None,
250}
251
252/// Represents instrument types on Coinbase International.
253#[derive(
254    Clone, Debug, Display, PartialEq, Eq, AsRefStr, EnumIter, EnumString, Serialize, Deserialize,
255)]
256#[serde(rename_all = "UPPERCASE")]
257pub enum CoinbaseIntxInstrumentType {
258    /// Spot products.
259    Spot,
260    /// Perpetual products.
261    Perp,
262    /// Index products.
263    Index,
264}
265
266/// Represents an asset status on Coinbase International.
267#[derive(
268    Clone, Debug, Display, PartialEq, Eq, AsRefStr, EnumIter, EnumString, Serialize, Deserialize,
269)]
270#[serde(rename_all = "UPPERCASE")]
271pub enum CoinbaseIntxAssetStatus {
272    /// Asset is actively trading.
273    Active,
274}
275
276/// Represents an instrument status on Coinbase International.
277#[derive(
278    Clone, Debug, Display, PartialEq, Eq, AsRefStr, EnumIter, EnumString, Serialize, Deserialize,
279)]
280#[serde(rename_all = "UPPERCASE")]
281pub enum CoinbaseIntxTradingState {
282    /// Instrument is actively trading.
283    Trading,
284    /// Instrument trading is paused.
285    Paused,
286    /// Instrument trading is halted.
287    Halt,
288    /// Instrument has been delisted.
289    Delisted,
290    /// TBD.
291    External,
292}