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