Skip to main content

nautilus_execution/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 nautilus_core::serialization::default_true;
17use nautilus_model::identifiers::ClientId;
18use serde::{Deserialize, Serialize};
19
20/// Configuration for `ExecutionEngine` instances.
21#[cfg_attr(
22    feature = "python",
23    pyo3::pyclass(
24        module = "nautilus_trader.core.nautilus_pyo3.execution",
25        from_py_object
26    )
27)]
28#[cfg_attr(
29    feature = "python",
30    pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.execution")
31)]
32#[derive(Debug, Clone, Serialize, Deserialize, bon::Builder)]
33#[serde(deny_unknown_fields)]
34pub struct ExecutionEngineConfig {
35    /// If the cache should be loaded on initialization.
36    #[serde(default = "default_true")]
37    #[builder(default = true)]
38    pub load_cache: bool,
39    /// If the execution engine should maintain own/user order books based on commands and events.
40    #[serde(default)]
41    #[builder(default)]
42    pub manage_own_order_books: bool,
43    /// If order state snapshot lists are persisted to a backing database.
44    /// Snapshots will be taken at every order state update (when events are applied).
45    #[serde(default)]
46    #[builder(default)]
47    pub snapshot_orders: bool,
48    /// If position state snapshot lists are persisted to a backing database.
49    /// Snapshots will be taken at position opened, changed and closed (when events are applied).
50    #[serde(default)]
51    #[builder(default)]
52    pub snapshot_positions: bool,
53    /// The interval (seconds) at which additional position state snapshots are persisted.
54    /// If `None` then no additional snapshots will be taken.
55    #[serde(default)]
56    pub snapshot_positions_interval_secs: Option<f64>,
57    /// If order fills exceeding order quantity are allowed (logs warning instead of raising).
58    /// Useful when position reconciliation races with exchange fill events.
59    #[serde(default)]
60    #[builder(default)]
61    pub allow_overfills: bool,
62    /// The client IDs declared for external stream processing.
63    ///
64    /// The execution engine will not attempt to send trading commands to these
65    /// client IDs, assuming an external process will consume the serialized
66    /// command messages from the bus and handle execution.
67    #[serde(default)]
68    pub external_clients: Option<Vec<ClientId>>,
69    /// The interval (minutes) between purging closed orders from the in-memory cache.
70    #[serde(default)]
71    pub purge_closed_orders_interval_mins: Option<u32>,
72    /// The time buffer (minutes) before closed orders can be purged.
73    #[serde(default)]
74    pub purge_closed_orders_buffer_mins: Option<u32>,
75    /// The interval (minutes) between purging closed positions from the in-memory cache.
76    #[serde(default)]
77    pub purge_closed_positions_interval_mins: Option<u32>,
78    /// The time buffer (minutes) before closed positions can be purged.
79    #[serde(default)]
80    pub purge_closed_positions_buffer_mins: Option<u32>,
81    /// The interval (minutes) between purging account events from the in-memory cache.
82    #[serde(default)]
83    pub purge_account_events_interval_mins: Option<u32>,
84    /// The time buffer (minutes) before account events can be purged.
85    #[serde(default)]
86    pub purge_account_events_lookback_mins: Option<u32>,
87    /// If purge operations should also delete from the backing database.
88    #[serde(default)]
89    #[builder(default)]
90    pub purge_from_database: bool,
91    /// If debug mode is active (will provide extra debug logging).
92    #[serde(default)]
93    #[builder(default)]
94    pub debug: bool,
95}
96
97impl Default for ExecutionEngineConfig {
98    fn default() -> Self {
99        Self::builder().build()
100    }
101}