nautilus_tardis/config.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 serde::{Deserialize, Serialize};
17
18use super::machine::types::ReplayNormalizedRequestOptions;
19
20/// Determines the output format for Tardis `book_snapshot_*` messages.
21#[derive(Debug, Clone, Default, Serialize, Deserialize)]
22#[serde(rename_all = "snake_case")]
23pub enum BookSnapshotOutput {
24 /// Convert book snapshots to `OrderBookDeltas` and write to `order_book_deltas/`.
25 #[default]
26 Deltas,
27 /// Convert book snapshots to `OrderBookDepth10` and write to `order_book_depths/`.
28 Depth10,
29}
30
31/// Provides a configuration for a Tarid Machine -> Nautilus data -> Parquet replay run.
32#[derive(Debug, Clone, Serialize, Deserialize)]
33pub struct TardisReplayConfig {
34 /// The Tardis Machine websocket url.
35 pub tardis_ws_url: Option<String>,
36 /// If symbols should be normalized with Nautilus conventions.
37 pub normalize_symbols: Option<bool>,
38 /// The output directory for writing Nautilus format Parquet files.
39 pub output_path: Option<String>,
40 /// The Tardis Machine replay options.
41 pub options: Vec<ReplayNormalizedRequestOptions>,
42 /// Optional WebSocket proxy URL.
43 ///
44 /// Note: WebSocket proxy support is not yet implemented. This field is reserved
45 /// for future functionality.
46 pub ws_proxy_url: Option<String>,
47 /// The output format for `book_snapshot_*` messages.
48 ///
49 /// - `deltas`: Convert to `OrderBookDeltas` and write to `order_book_deltas/` (default).
50 /// - `depth10`: Convert to `OrderBookDepth10` and write to `order_book_depths/`.
51 pub book_snapshot_output: Option<BookSnapshotOutput>,
52}
53
54/// Configuration for the Tardis data client.
55#[derive(Clone, Debug)]
56pub struct TardisDataClientConfig {
57 /// Tardis API key for HTTP instrument fetching.
58 /// Falls back to `TARDIS_API_KEY` env var if not set.
59 pub api_key: Option<String>,
60 /// Tardis Machine Server WebSocket URL.
61 /// Falls back to `TARDIS_MACHINE_WS_URL` env var if not set.
62 pub tardis_ws_url: Option<String>,
63 /// Whether to normalize symbols to Nautilus conventions.
64 pub normalize_symbols: bool,
65 /// Output format for `book_snapshot_*` messages.
66 pub book_snapshot_output: BookSnapshotOutput,
67 /// Replay options defining exchanges, symbols, date ranges, and data types.
68 pub options: Vec<ReplayNormalizedRequestOptions>,
69}
70
71impl Default for TardisDataClientConfig {
72 fn default() -> Self {
73 Self {
74 api_key: None,
75 tardis_ws_url: None,
76 normalize_symbols: true,
77 book_snapshot_output: BookSnapshotOutput::default(),
78 options: Vec::new(),
79 }
80 }
81}
82
83#[cfg(test)]
84mod tests {
85 use rstest::rstest;
86
87 use super::*;
88
89 #[rstest]
90 fn test_default_config_values() {
91 let config = TardisDataClientConfig::default();
92 assert!(config.api_key.is_none());
93 assert!(config.tardis_ws_url.is_none());
94 assert!(config.normalize_symbols);
95 assert!(matches!(
96 config.book_snapshot_output,
97 BookSnapshotOutput::Deltas
98 ));
99 assert!(config.options.is_empty());
100 }
101
102 #[rstest]
103 fn test_book_snapshot_output_default_is_deltas() {
104 assert!(matches!(
105 BookSnapshotOutput::default(),
106 BookSnapshotOutput::Deltas
107 ));
108 }
109
110 #[rstest]
111 fn test_book_snapshot_output_serde_roundtrip_deltas() {
112 let json = serde_json::to_string(&BookSnapshotOutput::Deltas).unwrap();
113 assert_eq!(json, "\"deltas\"");
114
115 let deserialized: BookSnapshotOutput = serde_json::from_str(&json).unwrap();
116 assert!(matches!(deserialized, BookSnapshotOutput::Deltas));
117 }
118
119 #[rstest]
120 fn test_book_snapshot_output_serde_roundtrip_depth10() {
121 let json = serde_json::to_string(&BookSnapshotOutput::Depth10).unwrap();
122 assert_eq!(json, "\"depth10\"");
123
124 let deserialized: BookSnapshotOutput = serde_json::from_str(&json).unwrap();
125 assert!(matches!(deserialized, BookSnapshotOutput::Depth10));
126 }
127}