Skip to main content

nautilus_data/engine/
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::{collections::HashMap, time::Duration};
17
18use nautilus_model::{
19    enums::{BarAggregation, BarIntervalType},
20    identifiers::ClientId,
21};
22
23/// Configuration for `DataEngine` instances.
24#[derive(Clone, Debug, bon::Builder)]
25pub struct DataEngineConfig {
26    /// If time bar aggregators will build and emit bars with no new market updates.
27    #[builder(default = true)]
28    pub time_bars_build_with_no_updates: bool,
29    /// If time bar aggregators will timestamp `ts_event` on bar close.
30    /// If False, then will timestamp on bar open.
31    #[builder(default = true)]
32    pub time_bars_timestamp_on_close: bool,
33    /// If time bar aggregators will skip emitting a bar if the aggregation starts mid-interval.
34    #[builder(default)]
35    pub time_bars_skip_first_non_full_bar: bool,
36    /// Determines the type of interval used for time aggregation.
37    /// - `LeftOpen`: start time is excluded and end time is included (default).
38    /// - `RightOpen`: start time is included and end time is excluded.
39    #[builder(default = BarIntervalType::LeftOpen)]
40    pub time_bars_interval_type: BarIntervalType,
41    /// The time delay (microseconds) before building and emitting a bar.
42    #[builder(default)]
43    pub time_bars_build_delay: u64,
44    /// A dictionary mapping time bar aggregations to their origin time offsets.
45    #[builder(default)]
46    pub time_bars_origins: HashMap<BarAggregation, Duration>,
47    /// If data objects timestamp sequencing will be validated and handled.
48    #[builder(default)]
49    pub validate_data_sequence: bool,
50    /// If order book deltas should be buffered until the `F_LAST` flag is set for a delta.
51    #[builder(default)]
52    pub buffer_deltas: bool,
53    /// The client IDs declared for external stream processing.
54    /// The data engine will not attempt to send data commands to these client IDs.
55    pub external_clients: Option<Vec<ClientId>>,
56    /// If debug mode is active (will provide extra debug logging).
57    #[builder(default)]
58    pub debug: bool,
59}
60
61impl DataEngineConfig {
62    #[allow(clippy::too_many_arguments)]
63    #[must_use]
64    pub const fn new(
65        time_bars_build_with_no_updates: bool,
66        time_bars_timestamp_on_close: bool,
67        time_bars_interval_type: BarIntervalType,
68        time_bars_skip_first_non_full_bar: bool,
69        time_bars_build_delay: u64,
70        time_bars_origins: HashMap<BarAggregation, Duration>,
71        validate_data_sequence: bool,
72        buffer_deltas: bool,
73        external_clients: Option<Vec<ClientId>>,
74        debug: bool,
75    ) -> Self {
76        Self {
77            time_bars_build_with_no_updates,
78            time_bars_timestamp_on_close,
79            time_bars_skip_first_non_full_bar,
80            time_bars_interval_type,
81            time_bars_build_delay,
82            time_bars_origins,
83            validate_data_sequence,
84            buffer_deltas,
85            external_clients,
86            debug,
87        }
88    }
89}
90
91impl Default for DataEngineConfig {
92    fn default() -> Self {
93        Self::builder().build()
94    }
95}