nautilus_data/engine/
config.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 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    /// A dictionary mapping time bar aggregations to their origin time offsets
38    pub time_bars_origins: HashMap<BarAggregation, Duration>,
39    /// If data objects timestamp sequencing will be validated and handled.
40    pub validate_data_sequence: bool,
41    /// If order book deltas should be buffered until the `F_LAST` flag is set for a delta.
42    pub buffer_deltas: bool,
43    /// The client IDs declared for external stream processing.
44    /// The data engine will not attempt to send data commands to these client IDs.
45    pub external_clients: Option<Vec<ClientId>>,
46    /// If debug mode is active (will provide extra debug logging).
47    pub debug: bool,
48}
49
50impl DataEngineConfig {
51    #[allow(clippy::too_many_arguments)]
52    #[must_use]
53    pub const fn new(
54        time_bars_build_with_no_updates: bool,
55        time_bars_timestamp_on_close: bool,
56        time_bars_interval_type: BarIntervalType,
57        time_bars_skip_first_non_full_bar: bool,
58        time_bars_origins: HashMap<BarAggregation, Duration>,
59        validate_data_sequence: bool,
60        buffer_deltas: bool,
61        external_clients: Option<Vec<ClientId>>,
62        debug: bool,
63    ) -> Self {
64        Self {
65            time_bars_build_with_no_updates,
66            time_bars_timestamp_on_close,
67            time_bars_skip_first_non_full_bar,
68            time_bars_interval_type,
69            time_bars_origins,
70            validate_data_sequence,
71            buffer_deltas,
72            external_clients,
73            debug,
74        }
75    }
76}
77
78impl Default for DataEngineConfig {
79    fn default() -> Self {
80        Self {
81            time_bars_build_with_no_updates: true,
82            time_bars_timestamp_on_close: true,
83            time_bars_interval_type: BarIntervalType::LeftOpen,
84            validate_data_sequence: false,
85            buffer_deltas: false,
86            external_clients: None,
87            debug: false,
88            time_bars_skip_first_non_full_bar: false,
89            time_bars_origins: HashMap::new(),
90        }
91    }
92}