Skip to main content

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