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