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// -------------------------------------------------------------------------------------------------
1516use nautilus_common::{
17 cache::CacheConfig, enums::Environment, logging::logger::LoggerConfig,
18 msgbus::database::MessageBusConfig,
19};
20use nautilus_core::UUID4;
21use nautilus_data::engine::config::DataEngineConfig;
22use nautilus_execution::engine::config::ExecutionEngineConfig;
23use nautilus_model::identifiers::TraderId;
24use nautilus_persistence::config::StreamingConfig;
25use nautilus_portfolio::config::PortfolioConfig;
26use nautilus_risk::engine::config::RiskEngineConfig;
2728#[derive(Debug, Clone)]
29/// Configuration for a `NautilusKernel` core system instance.
30pub struct NautilusKernelConfig {
31/// The kernel environment context.
32pub environment: Environment,
33/// The trader ID for the node (must be a name and ID tag separated by a hyphen).
34pub trader_id: TraderId,
35/// If trading strategy state should be loaded from the database on start.
36pub load_state: bool,
37/// If trading strategy state should be saved to the database on stop.
38pub save_state: bool,
39/// The logging configuration for the kernel.
40pub logging: LoggerConfig,
41/// The unique instance identifier for the kernel
42pub instance_id: Option<UUID4>,
43/// The timeout (seconds) for all clients to connect and initialize.
44pub timeout_connection: u32,
45/// The timeout (seconds) for execution state to reconcile.
46pub timeout_reconciliation: u32,
47/// The timeout (seconds) for portfolio to initialize margins and unrealized pnls.
48pub timeout_portfolio: u32,
49/// The timeout (seconds) for all engine clients to disconnect.
50pub timeout_disconnection: u32,
51/// The timeout (seconds) after stopping the node to await residual events before final shutdown.
52pub timeout_post_stop: u32,
53/// The timeout (seconds) to await pending tasks cancellation during shutdown.
54pub timeout_shutdown: u32,
55/// The cache configuration.
56pub cache: Option<CacheConfig>,
57/// The message bus configuration.
58pub msgbus: Option<MessageBusConfig>,
59/// The data engine configuration.
60pub data_engine: Option<DataEngineConfig>,
61/// The risk engine configuration.
62pub risk_engine: Option<RiskEngineConfig>,
63/// The execution engine configuration.
64pub exec_engine: Option<ExecutionEngineConfig>,
65/// The portfolio configuration.
66pub portfolio: Option<PortfolioConfig>,
67/// The configuration for streaming to feather files.
68pub streaming: Option<StreamingConfig>,
69}
7071impl NautilusKernelConfig {
72#[allow(clippy::too_many_arguments)]
73 #[must_use]
74pub fn new(
75 environment: Environment,
76 trader_id: TraderId,
77 load_state: Option<bool>,
78 save_state: Option<bool>,
79 timeout_connection: Option<u32>,
80 timeout_reconciliation: Option<u32>,
81 timeout_portfolio: Option<u32>,
82 timeout_disconnection: Option<u32>,
83 timeout_post_stop: Option<u32>,
84 timeout_shutdown: Option<u32>,
85 logging: Option<LoggerConfig>,
86 instance_id: Option<UUID4>,
87 cache: Option<CacheConfig>,
88 msgbus: Option<MessageBusConfig>,
89 data_engine: Option<DataEngineConfig>,
90 risk_engine: Option<RiskEngineConfig>,
91 exec_engine: Option<ExecutionEngineConfig>,
92 portfolio: Option<PortfolioConfig>,
93 streaming: Option<StreamingConfig>,
94 ) -> Self {
95Self {
96 environment,
97 trader_id,
98 instance_id,
99 cache,
100 msgbus,
101 data_engine,
102 risk_engine,
103 exec_engine,
104 portfolio,
105 streaming,
106 load_state: load_state.unwrap_or(true),
107 save_state: save_state.unwrap_or(true),
108 timeout_connection: timeout_connection.unwrap_or(60),
109 timeout_reconciliation: timeout_reconciliation.unwrap_or(30),
110 timeout_portfolio: timeout_portfolio.unwrap_or(10),
111 timeout_disconnection: timeout_disconnection.unwrap_or(10),
112 timeout_post_stop: timeout_post_stop.unwrap_or(10),
113 timeout_shutdown: timeout_shutdown.unwrap_or(5),
114 logging: logging.unwrap_or_default(),
115 }
116 }
117}
118119impl Default for NautilusKernelConfig {
120fn default() -> Self {
121Self {
122 environment: Environment::Backtest,
123 trader_id: TraderId::default(),
124 load_state: false,
125 save_state: false,
126 logging: LoggerConfig::default(),
127 instance_id: None,
128 timeout_connection: 60,
129 timeout_reconciliation: 30,
130 timeout_portfolio: 10,
131 timeout_disconnection: 10,
132 timeout_post_stop: 10,
133 timeout_shutdown: 5,
134 cache: None,
135 msgbus: None,
136 data_engine: None,
137 risk_engine: None,
138 exec_engine: None,
139 portfolio: None,
140 streaming: None,
141 }
142 }
143}