nautilus_tardis/http/
models.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 chrono::{DateTime, Utc};
17use serde::Deserialize;
18use ustr::Ustr;
19
20use crate::{
21    enums::{Exchange, InstrumentType, OptionType},
22    parse::deserialize_uppercase,
23};
24
25#[derive(Debug, Clone, Deserialize)]
26#[serde(rename_all = "camelCase")]
27/// The metadata of a particular instrument.
28/// See <https://docs.tardis.dev/api/instruments-metadata-api>.
29pub struct InstrumentInfo {
30    /// The instrument symbol.
31    #[serde(deserialize_with = "deserialize_uppercase")]
32    pub id: Ustr,
33    /// The instrument exchange.
34    pub exchange: Exchange,
35    /// The instrument base currency (normalized, e.g., BTC for `BitMEX`, not XBT).
36    pub base_currency: Ustr,
37    /// The instrument quote currency (normalized, e.g., BTC for `BitMEX`, not XBT).
38    pub quote_currency: Ustr,
39    /// The instrument type e.g., spot, perpetual, future, option.
40    #[serde(rename = "type")]
41    pub instrument_type: InstrumentType,
42    /// If the instrument is actively listed.
43    pub active: bool,
44    /// The listing date in ISO format.
45    pub listing: Option<DateTime<Utc>>,
46    /// The available from date in ISO format.
47    pub available_since: DateTime<Utc>,
48    /// The available to date in ISO format.
49    pub available_to: Option<DateTime<Utc>>,
50    /// The contract expiry date in ISO format (applicable to futures and options).
51    pub expiry: Option<DateTime<Utc>>,
52    /// The instrument price increment.
53    pub price_increment: f64,
54    /// The instrument size increment.
55    pub amount_increment: f64,
56    /// The minimum tradeable size for the instrument.
57    pub min_trade_amount: f64,
58    /// 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.
59    pub maker_fee: f64,
60    /// 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.
61    pub taker_fee: f64,
62    /// If the instrument is inverse (only for derivatives such as futures and perpetual swaps).
63    pub inverse: Option<bool>,
64    /// The instrument contract multiplier (only for derivatives).
65    pub contract_multiplier: Option<f64>,
66    /// If the instrument is quanto (only for quanto instruments).
67    pub quanto: Option<bool>,
68    /// The instrument settlement currency (only for Quanto instruments where settlement currency is different both base and quote currency).
69    pub settlement_currency: Option<Ustr>,
70    /// The instrument strike price (only for options).
71    pub strike_price: Option<f64>,
72    /// The option type (only for options).
73    pub option_type: Option<OptionType>,
74    /// The changes for the instrument (best-effort basis from Tardis).
75    pub changes: Option<Vec<InstrumentChanges>>,
76}
77
78#[derive(Debug, Clone, Deserialize)]
79#[serde(rename_all = "camelCase")]
80/// The changes info returned by the exchanges API.
81pub struct InstrumentChanges {
82    /// Date in ISO format.
83    pub until: DateTime<Utc>,
84    /// The minimum price increment (tick size).
85    #[serde(skip_serializing_if = "Option::is_none")]
86    #[serde(default)]
87    pub price_increment: Option<f64>,
88    /// The minimum size increment.
89    #[serde(skip_serializing_if = "Option::is_none")]
90    #[serde(default)]
91    pub amount_increment: Option<f64>,
92    /// The instrument contract multiplier (only for derivatives).
93    #[serde(skip_serializing_if = "Option::is_none")]
94    #[serde(default)]
95    pub contract_multiplier: Option<f64>,
96    /// The maker fee rate.
97    #[serde(skip_serializing_if = "Option::is_none")]
98    #[serde(default)]
99    pub maker_fee: Option<f64>,
100    /// The taker fee rate.
101    #[serde(skip_serializing_if = "Option::is_none")]
102    #[serde(default)]
103    pub taker_fee: Option<f64>,
104}