nautilus_tardis/
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::identifiers::Venue;
17use serde::{Deserialize, Serialize};
18use strum::{AsRefStr, Display, EnumIter, EnumString, FromRepr};
19use ustr::Ustr;
20
21#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Display)]
22#[serde(rename_all = "lowercase")]
23/// The instrument type for the symbol.
24pub enum InstrumentType {
25    Spot,
26    Perpetual,
27    Future,
28    Option,
29    Combo,
30}
31
32#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Display)]
33#[serde(rename_all = "lowercase")]
34/// The type of option.
35pub enum OptionType {
36    Call,
37    Put,
38}
39
40/// The aggressor side of the trade.
41#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Display)]
42#[serde(rename_all = "lowercase")]
43pub enum TradeSide {
44    Buy,
45    Sell,
46    Unknown,
47}
48
49/// The bar kind.
50#[allow(missing_docs)]
51#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Display)]
52#[serde(rename_all = "lowercase")]
53pub enum BarKind {
54    Time,
55    Volume,
56    Tick,
57}
58
59#[derive(
60    Debug,
61    Clone,
62    PartialEq,
63    Eq,
64    Hash,
65    Serialize,
66    Deserialize,
67    Display,
68    AsRefStr,
69    EnumIter,
70    EnumString,
71    FromRepr,
72)]
73#[strum(ascii_case_insensitive)]
74#[strum(serialize_all = "kebab-case")]
75#[serde(rename_all = "kebab-case")]
76/// Represents a crypto exchange.
77/// See <https://api.tardis.dev/v1/exchanges> for all supported exchanges.
78pub enum Exchange {
79    Ascendex,
80    Binance,
81    BinanceDelivery,
82    BinanceDex,
83    BinanceFutures,
84    BinanceJersey,
85    BinanceOptions,
86    BinanceUs,
87    Bitfinex,
88    BitfinexDerivatives,
89    Bitflyer,
90    Bitmex,
91    Bitnomial,
92    Bitstamp,
93    BlockchainCom,
94    Bybit,
95    BybitOptions,
96    BybitSpot,
97    Coinbase,
98    Coinflex,
99    CryptoCom,
100    CryptoComDerivatives,
101    Cryptofacilities,
102    Delta,
103    Deribit,
104    Dydx,
105    Ftx,
106    FtxUs,
107    GateIo,
108    GateIoFutures,
109    Gemini,
110    Hitbtc,
111    Huobi,
112    HuobiDm,
113    HuobiDmLinearSwap,
114    HuobiDmOptions,
115    HuobiDmSwap,
116    Kraken,
117    Kucoin,
118    Mango,
119    Okcoin,
120    Okex,
121    OkexFutures,
122    OkexOptions,
123    OkexSwap,
124    Phemex,
125    Poloniex,
126    Serum,
127    StarAtlas,
128    Upbit,
129    WooX,
130}
131
132impl Exchange {
133    #[must_use]
134    pub fn from_venue_str(s: &str) -> Vec<Self> {
135        let s = s.to_ascii_uppercase();
136        match s.as_str() {
137            "ASCENDEX" => vec![Self::Ascendex],
138            "BINANCE" => vec![
139                Self::Binance,
140                Self::BinanceDex,
141                Self::BinanceFutures,
142                Self::BinanceJersey,
143                Self::BinanceOptions,
144            ],
145            "BINANCE_DELIVERY" => vec![Self::BinanceDelivery],
146            "BINANCE_US" => vec![Self::BinanceUs],
147            "BITFINEX" => vec![Self::Bitfinex, Self::BitfinexDerivatives],
148            "BITFLYER" => vec![Self::Bitflyer],
149            "BITMEX" => vec![Self::Bitmex],
150            "BITNOMIAL" => vec![Self::Bitnomial],
151            "BITSTAMP" => vec![Self::Bitstamp],
152            "BLOCKCHAIN_COM" => vec![Self::BlockchainCom],
153            "BYBIT" => vec![Self::Bybit, Self::BybitOptions, Self::BybitSpot],
154            "COINBASE" => vec![Self::Coinbase],
155            "COINFLEX" => vec![Self::Coinflex],
156            "CRYPTO_COM" => vec![Self::CryptoCom, Self::CryptoComDerivatives],
157            "CRYPTOFACILITIES" => vec![Self::Cryptofacilities],
158            "DELTA" => vec![Self::Delta],
159            "DERIBIT" => vec![Self::Deribit],
160            "DYDX" => vec![Self::Dydx],
161            "FTX" => vec![Self::Ftx, Self::FtxUs],
162            "GATE_IO" => vec![Self::GateIo, Self::GateIoFutures],
163            "GEMINI" => vec![Self::Gemini],
164            "HITBTC" => vec![Self::Hitbtc],
165            "HUOBI" => vec![
166                Self::Huobi,
167                Self::HuobiDm,
168                Self::HuobiDmLinearSwap,
169                Self::HuobiDmOptions,
170                Self::HuobiDmSwap,
171            ],
172            "KRAKEN" => vec![Self::Kraken],
173            "KUCOIN" => vec![Self::Kucoin],
174            "MANGO" => vec![Self::Mango],
175            "OKCOIN" => vec![Self::Okcoin],
176            "OKEX" => vec![
177                Self::Okex,
178                Self::OkexFutures,
179                Self::OkexOptions,
180                Self::OkexSwap,
181            ],
182            "PHEMEX" => vec![Self::Phemex],
183            "POLONIEX" => vec![Self::Poloniex],
184            "SERUM" => vec![Self::Serum],
185            "STARATLAS" => vec![Self::StarAtlas],
186            "UPBIT" => vec![Self::Upbit],
187            "WOO_X" => vec![Self::WooX],
188            _ => Vec::new(),
189        }
190    }
191
192    #[must_use]
193    pub const fn as_venue_str(&self) -> &str {
194        match self {
195            Self::Ascendex => "ASCENDEX",
196            Self::Binance => "BINANCE",
197            Self::BinanceDelivery => "BINANCE_DELIVERY",
198            Self::BinanceDex => "BINANCE",
199            Self::BinanceFutures => "BINANCE",
200            Self::BinanceJersey => "BINANCE",
201            Self::BinanceOptions => "BINANCE",
202            Self::BinanceUs => "BINANCE_US",
203            Self::Bitfinex => "BITFINEX",
204            Self::BitfinexDerivatives => "BITFINEX",
205            Self::Bitflyer => "BITFLYER",
206            Self::Bitmex => "BITMEX",
207            Self::Bitnomial => "BITNOMIAL",
208            Self::Bitstamp => "BITSTAMP",
209            Self::BlockchainCom => "BLOCKCHAIN_COM",
210            Self::Bybit => "BYBIT",
211            Self::BybitOptions => "BYBIT",
212            Self::BybitSpot => "BYBIT",
213            Self::Coinbase => "COINBASE",
214            Self::Coinflex => "COINFLEX",
215            Self::CryptoCom => "CRYPTO_COM",
216            Self::CryptoComDerivatives => "CRYPTO_COM",
217            Self::Cryptofacilities => "CRYPTOFACILITIES",
218            Self::Delta => "DELTA",
219            Self::Deribit => "DERIBIT",
220            Self::Dydx => "DYDX",
221            Self::Ftx => "FTX",
222            Self::FtxUs => "FTX",
223            Self::GateIo => "GATE_IO",
224            Self::GateIoFutures => "GATE_IO",
225            Self::Gemini => "GEMINI",
226            Self::Hitbtc => "HITBTC",
227            Self::Huobi => "HUOBI",
228            Self::HuobiDm => "HUOBI",
229            Self::HuobiDmLinearSwap => "HUOBI",
230            Self::HuobiDmOptions => "HUOBI",
231            Self::HuobiDmSwap => "HUOBI",
232            Self::Kraken => "KRAKEN",
233            Self::Kucoin => "KUCOIN",
234            Self::Mango => "MANGO",
235            Self::Okcoin => "OKCOIN",
236            Self::Okex => "OKEX",
237            Self::OkexFutures => "OKEX",
238            Self::OkexOptions => "OKEX",
239            Self::OkexSwap => "OKEX",
240            Self::Phemex => "PHEMEX",
241            Self::Poloniex => "POLONIEX",
242            Self::Serum => "SERUM",
243            Self::StarAtlas => "STARATLAS",
244            Self::Upbit => "UPBIT",
245            Self::WooX => "WOO_X",
246        }
247    }
248
249    #[must_use]
250    pub fn as_venue(&self) -> Venue {
251        Venue::from_ustr_unchecked(Ustr::from(self.as_venue_str()))
252    }
253}