Skip to main content

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