nautilus_tardis/machine/types.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::NaiveDate;
17use nautilus_model::identifiers::InstrumentId;
18use serde::{Deserialize, Serialize};
19use ustr::Ustr;
20
21use crate::enums::TardisExchange;
22pub use crate::machine::client::TardisMachineClient;
23
24/// Instrument definition information necessary for stream parsing.
25#[derive(Clone, Debug, Serialize, Deserialize)]
26#[cfg_attr(
27 feature = "python",
28 pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.tardis")
29)]
30pub struct TardisInstrumentMiniInfo {
31 /// The instrument ID with optionally Nautilus normalized symbol.
32 pub instrument_id: InstrumentId,
33 /// The Tardis symbol.
34 pub raw_symbol: Ustr,
35 /// The Tardis exchange.
36 pub exchange: TardisExchange,
37 /// The price precision for the instrument.
38 pub price_precision: u8,
39 /// The size precision for the instrument.
40 pub size_precision: u8,
41}
42
43impl TardisInstrumentMiniInfo {
44 /// Creates a new [`TardisInstrumentMiniInfo`] instance.
45 ///
46 /// If `raw_instrument_id` is `None` then the `instrument_id` value will be assigned.
47 #[must_use]
48 pub fn new(
49 instrument_id: InstrumentId,
50 raw_symbol: Option<Ustr>,
51 exchange: TardisExchange,
52 price_precision: u8,
53 size_precision: u8,
54 ) -> Self {
55 Self {
56 instrument_id,
57 raw_symbol: raw_symbol.unwrap_or(Ustr::from(instrument_id.symbol.as_str())),
58 exchange,
59 price_precision,
60 size_precision,
61 }
62 }
63
64 #[must_use]
65 pub const fn as_tardis_instrument_key(&self) -> TardisInstrumentKey {
66 TardisInstrumentKey::new(self.raw_symbol, self.exchange)
67 }
68}
69
70/// Instrument definition information necessary for stream parsing.
71#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
72#[cfg_attr(
73 feature = "python",
74 pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.tardis")
75)]
76pub struct TardisInstrumentKey {
77 /// The Tardis raw symbol.
78 pub raw_symbol: Ustr,
79 /// The Tardis exchange.
80 pub exchange: TardisExchange,
81}
82
83impl TardisInstrumentKey {
84 /// Creates a new [`TardisInstrumentKey`] instance.
85 #[must_use]
86 pub const fn new(raw_symbol: Ustr, exchange: TardisExchange) -> Self {
87 Self {
88 raw_symbol,
89 exchange,
90 }
91 }
92}
93
94/// The options that can be specified for calling Tardis Machine Server's replay-normalized.
95#[derive(Debug, Clone, Serialize, Deserialize)]
96#[serde(rename_all = "camelCase")]
97#[cfg_attr(
98 feature = "python",
99 pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.tardis")
100)]
101pub struct ReplayNormalizedRequestOptions {
102 /// Requested [`TardisExchange`].
103 pub exchange: TardisExchange,
104 /// Optional symbols of requested historical data feed.
105 /// Use /exchanges/:exchange HTTP API to get allowed symbols for requested exchange.
106 #[serde(skip_serializing_if = "Option::is_none")]
107 #[serde(default)]
108 pub symbols: Option<Vec<String>>,
109 /// Replay period start date (UTC) in a ISO 8601 format, e.g., 2019-10-01.
110 pub from: NaiveDate,
111 /// Replay period start date (UTC) in a ISO 8601 format, e.g., 2019-10-02.
112 pub to: NaiveDate,
113 /// Array of normalized [data types](https://docs.tardis.dev/api/tardis-machine#normalized-data-types)
114 /// for which real-time data will be provided.
115 #[serde(alias = "data_types")]
116 pub data_types: Vec<String>,
117 /// When set to true, sends also disconnect messages that mark events when real-time WebSocket
118 /// connection that was used to collect the historical data got disconnected.
119 #[serde(skip_serializing_if = "Option::is_none")]
120 #[serde(default)]
121 #[serde(alias = "with_disconnect_messages")]
122 pub with_disconnect_messages: Option<bool>,
123}
124
125/// The options that can be specified for calling Tardis Machine Server's stream-normalized.
126#[derive(Debug, Clone, Serialize, Deserialize)]
127#[serde(rename_all = "camelCase")]
128#[cfg_attr(
129 feature = "python",
130 pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.tardis")
131)]
132pub struct StreamNormalizedRequestOptions {
133 /// Requested [`TardisExchange`].
134 pub exchange: TardisExchange,
135 /// Optional symbols of requested real-time data feed.
136 #[serde(skip_serializing_if = "Option::is_none")]
137 #[serde(default)]
138 pub symbols: Option<Vec<String>>,
139 /// Array of normalized [data types](https://docs.tardis.dev/api/tardis-machine#normalized-data-types)
140 /// for which real-time data will be provided.
141 #[serde(alias = "data_types")]
142 pub data_types: Vec<String>,
143 /// When set to true, sends disconnect messages anytime underlying exchange real-time WebSocket
144 /// connection(s) gets disconnected.
145 #[serde(skip_serializing_if = "Option::is_none")]
146 #[serde(default)]
147 pub with_disconnect_messages: Option<bool>,
148 /// Specifies time in milliseconds after which connection to real-time exchanges' WebSocket API
149 /// is restarted if no message has been received.
150 #[serde(skip_serializing_if = "Option::is_none")]
151 #[serde(default, rename = "timeoutIntervalMS")]
152 pub timeout_interval_ms: Option<u64>,
153}