nautilus_tardis/
enums.rs

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