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