nautilus_testkit/testers/data/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 std::num::NonZeroUsize;
17
18use nautilus_common::actor::DataActorConfig;
19use nautilus_core::Params;
20use nautilus_model::{
21 data::bar::BarType,
22 enums::BookType,
23 identifiers::{ClientId, InstrumentId},
24};
25
26/// Configuration for the data tester actor.
27#[derive(Debug, Clone, bon::Builder)]
28pub struct DataTesterConfig {
29 /// Base data actor configuration.
30 #[builder(default)]
31 pub base: DataActorConfig,
32 /// Instrument IDs to subscribe to.
33 #[builder(default)]
34 pub instrument_ids: Vec<InstrumentId>,
35 /// Client ID to use for subscriptions.
36 pub client_id: Option<ClientId>,
37 /// Bar types to subscribe to.
38 pub bar_types: Option<Vec<BarType>>,
39 /// Whether to subscribe to order book deltas.
40 #[builder(default = false)]
41 pub subscribe_book_deltas: bool,
42 /// Whether to subscribe to order book depth snapshots.
43 #[builder(default = false)]
44 pub subscribe_book_depth: bool,
45 /// Whether to subscribe to order book at interval.
46 #[builder(default = false)]
47 pub subscribe_book_at_interval: bool,
48 /// Whether to subscribe to quotes.
49 #[builder(default = false)]
50 pub subscribe_quotes: bool,
51 /// Whether to subscribe to trades.
52 #[builder(default = false)]
53 pub subscribe_trades: bool,
54 /// Whether to subscribe to mark prices.
55 #[builder(default = false)]
56 pub subscribe_mark_prices: bool,
57 /// Whether to subscribe to index prices.
58 #[builder(default = false)]
59 pub subscribe_index_prices: bool,
60 /// Whether to subscribe to funding rates.
61 #[builder(default = false)]
62 pub subscribe_funding_rates: bool,
63 /// Whether to subscribe to bars.
64 #[builder(default = false)]
65 pub subscribe_bars: bool,
66 /// Whether to subscribe to instrument updates.
67 #[builder(default = false)]
68 pub subscribe_instrument: bool,
69 /// Whether to subscribe to instrument status.
70 #[builder(default = false)]
71 pub subscribe_instrument_status: bool,
72 /// Whether to subscribe to instrument close.
73 #[builder(default = false)]
74 pub subscribe_instrument_close: bool,
75 /// Whether to subscribe to option greeks.
76 #[builder(default = false)]
77 pub subscribe_option_greeks: bool,
78 /// Optional parameters passed to all subscribe calls.
79 pub subscribe_params: Option<Params>,
80 /// Optional parameters passed to all request calls.
81 pub request_params: Option<Params>,
82 /// Whether unsubscribe is supported on stop.
83 #[builder(default = true)]
84 pub can_unsubscribe: bool,
85 /// Whether to request instruments on start.
86 #[builder(default = false)]
87 pub request_instruments: bool,
88 // TODO: Support request_quotes when historical data requests are available
89 /// Whether to request historical quotes (not yet implemented).
90 #[builder(default = false)]
91 pub request_quotes: bool,
92 // TODO: Support request_trades when historical data requests are available
93 /// Whether to request historical trades (not yet implemented).
94 #[builder(default = false)]
95 pub request_trades: bool,
96 /// Whether to request historical bars.
97 #[builder(default = false)]
98 pub request_bars: bool,
99 /// Whether to request order book snapshots.
100 #[builder(default = false)]
101 pub request_book_snapshot: bool,
102 // TODO: Support request_book_deltas when Rust data engine has RequestBookDeltas
103 /// Whether to request historical order book deltas (not yet implemented).
104 #[builder(default = false)]
105 pub request_book_deltas: bool,
106 /// Whether to request historical funding rates.
107 #[builder(default = false)]
108 pub request_funding_rates: bool,
109 // TODO: Support requests_start_delta when we implement historical data requests
110 /// Book type for order book subscriptions.
111 #[builder(default = BookType::L2_MBP)]
112 pub book_type: BookType,
113 /// Order book depth for subscriptions.
114 pub book_depth: Option<NonZeroUsize>,
115 // TODO: Support book_group_size when order book grouping is implemented
116 /// Order book interval in milliseconds for at_interval subscriptions.
117 #[builder(default = NonZeroUsize::new(1000).unwrap())]
118 pub book_interval_ms: NonZeroUsize,
119 /// Number of order book levels to print when logging.
120 #[builder(default = 10)]
121 pub book_levels_to_print: usize,
122 /// Whether to manage local order book from deltas.
123 #[builder(default = true)]
124 pub manage_book: bool,
125 /// Whether to log received data.
126 #[builder(default = true)]
127 pub log_data: bool,
128 /// Stats logging interval in seconds (0 to disable).
129 #[builder(default = 5)]
130 pub stats_interval_secs: u64,
131}
132
133impl DataTesterConfig {
134 /// Creates a new [`DataTesterConfig`] instance with minimal settings.
135 ///
136 /// # Panics
137 ///
138 /// Panics if `NonZeroUsize::new(1000)` fails (which should never happen).
139 #[must_use]
140 pub fn new(client_id: ClientId, instrument_ids: Vec<InstrumentId>) -> Self {
141 Self {
142 base: DataActorConfig::default(),
143 instrument_ids,
144 client_id: Some(client_id),
145 bar_types: None,
146 subscribe_book_deltas: false,
147 subscribe_book_depth: false,
148 subscribe_book_at_interval: false,
149 subscribe_quotes: false,
150 subscribe_trades: false,
151 subscribe_mark_prices: false,
152 subscribe_index_prices: false,
153 subscribe_funding_rates: false,
154 subscribe_bars: false,
155
156 subscribe_instrument: false,
157 subscribe_instrument_status: false,
158 subscribe_instrument_close: false,
159 subscribe_option_greeks: false,
160 subscribe_params: None,
161 request_params: None,
162 can_unsubscribe: true,
163 request_instruments: false,
164 request_quotes: false,
165 request_trades: false,
166 request_bars: false,
167 request_book_snapshot: false,
168 request_book_deltas: false,
169 request_funding_rates: false,
170 book_type: BookType::L2_MBP,
171 book_depth: None,
172 book_interval_ms: NonZeroUsize::new(1000).unwrap(),
173 book_levels_to_print: 10,
174 manage_book: true,
175 log_data: true,
176 stats_interval_secs: 5,
177 }
178 }
179}
180
181impl Default for DataTesterConfig {
182 fn default() -> Self {
183 Self::builder().build()
184 }
185}