nautilus_tardis/http/models.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2026 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 chrono::{DateTime, Utc};
17use serde::{Deserialize, Serialize};
18use serde_json::Value;
19use ustr::Ustr;
20
21use crate::common::{
22 enums::{TardisExchange, TardisInstrumentType, TardisOptionType},
23 parse::deserialize_uppercase,
24};
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(rename_all = "camelCase")]
28/// The metadata of a particular instrument.
29/// See <https://docs.tardis.dev/api/instruments-metadata-api>.
30pub struct TardisInstrumentInfo {
31 /// The instrument symbol.
32 #[serde(deserialize_with = "deserialize_uppercase")]
33 pub id: Ustr,
34 /// The instrument exchange.
35 pub exchange: TardisExchange,
36 /// The instrument base currency (normalized, e.g., BTC for BitMEX, not XBT).
37 pub base_currency: Ustr,
38 /// The instrument quote currency (normalized, e.g., BTC for BitMEX, not XBT).
39 pub quote_currency: Ustr,
40 /// The instrument type e.g., spot, perpetual, future, option.
41 #[serde(rename = "type")]
42 pub instrument_type: TardisInstrumentType,
43 /// If the instrument is actively listed.
44 pub active: bool,
45 /// The listing date in ISO format.
46 #[serde(skip_serializing_if = "Option::is_none")]
47 pub listing: Option<DateTime<Utc>>,
48 /// The available from date in ISO format.
49 pub available_since: DateTime<Utc>,
50 /// The available to date in ISO format.
51 #[serde(skip_serializing_if = "Option::is_none")]
52 pub available_to: Option<DateTime<Utc>>,
53 /// The contract expiry date in ISO format (applicable to futures and options).
54 #[serde(skip_serializing_if = "Option::is_none")]
55 pub expiry: Option<DateTime<Utc>>,
56 /// The instrument price increment.
57 pub price_increment: f64,
58 /// The instrument size increment.
59 pub amount_increment: f64,
60 /// The minimum tradeable size for the instrument.
61 pub min_trade_amount: f64,
62 /// The instrument maker fee: consider it as illustrative only, as it depends in practice on account traded volume levels, different categories, VIP levels, owning exchange currency etc.
63 pub maker_fee: f64,
64 /// The instrument taker fee: consider it as illustrative only, as it depends in practice on account traded volume levels, different categories, VIP levels, owning exchange currency etc.
65 pub taker_fee: f64,
66 /// If the instrument is inverse (only for derivatives such as futures and perpetual swaps).
67 #[serde(skip_serializing_if = "Option::is_none")]
68 pub inverse: Option<bool>,
69 /// The instrument contract multiplier (only for derivatives).
70 #[serde(skip_serializing_if = "Option::is_none")]
71 pub contract_multiplier: Option<f64>,
72 /// If the instrument is quanto (only for quanto instruments).
73 #[serde(skip_serializing_if = "Option::is_none")]
74 pub quanto: Option<bool>,
75 /// The instrument settlement currency (only for Quanto instruments where settlement currency is different both base and quote currency).
76 #[serde(skip_serializing_if = "Option::is_none")]
77 pub settlement_currency: Option<Ustr>,
78 /// The instrument strike price (only for options).
79 #[serde(skip_serializing_if = "Option::is_none")]
80 pub strike_price: Option<f64>,
81 /// The option type (only for options).
82 #[serde(skip_serializing_if = "Option::is_none")]
83 pub option_type: Option<TardisOptionType>,
84 /// The changes for the instrument (best-effort basis from Tardis).
85 #[serde(skip_serializing_if = "Option::is_none")]
86 pub changes: Option<Vec<TardisInstrumentChanges>>,
87 /// Additional fields from the Tardis API not explicitly modeled above.
88 #[serde(flatten)]
89 pub extra: serde_json::Map<String, Value>,
90}
91
92#[derive(Debug, Clone, Serialize, Deserialize)]
93#[serde(rename_all = "camelCase")]
94/// The changes info returned by the exchanges API.
95pub struct TardisInstrumentChanges {
96 /// Date in ISO format.
97 pub until: DateTime<Utc>,
98 /// The minimum price increment (tick size).
99 #[serde(skip_serializing_if = "Option::is_none")]
100 #[serde(default)]
101 pub price_increment: Option<f64>,
102 /// The minimum size increment.
103 #[serde(skip_serializing_if = "Option::is_none")]
104 #[serde(default)]
105 pub amount_increment: Option<f64>,
106 /// The instrument contract multiplier (only for derivatives).
107 #[serde(skip_serializing_if = "Option::is_none")]
108 #[serde(default)]
109 pub contract_multiplier: Option<f64>,
110 /// The maker fee rate.
111 #[serde(skip_serializing_if = "Option::is_none")]
112 #[serde(default)]
113 pub maker_fee: Option<f64>,
114 /// The taker fee rate.
115 #[serde(skip_serializing_if = "Option::is_none")]
116 #[serde(default)]
117 pub taker_fee: Option<f64>,
118 /// Additional fields from the Tardis API not explicitly modeled above.
119 #[serde(flatten)]
120 pub extra: serde_json::Map<String, Value>,
121}