nautilus_system/
config.rs1use std::{fmt::Debug, time::Duration};
17
18use nautilus_common::{
19 cache::CacheConfig, enums::Environment, logging::logger::LoggerConfig,
20 msgbus::database::MessageBusConfig,
21};
22use nautilus_core::{UUID4, UnixNanos};
23use nautilus_data::engine::config::DataEngineConfig;
24use nautilus_execution::engine::config::ExecutionEngineConfig;
25use nautilus_model::identifiers::TraderId;
26use nautilus_portfolio::config::PortfolioConfig;
27use nautilus_risk::engine::config::RiskEngineConfig;
28
29pub trait NautilusKernelConfig: Debug {
31 fn environment(&self) -> Environment;
33 fn trader_id(&self) -> TraderId;
35 fn load_state(&self) -> bool;
37 fn save_state(&self) -> bool;
39 fn logging(&self) -> LoggerConfig;
41 fn instance_id(&self) -> Option<UUID4>;
43 fn timeout_connection(&self) -> Duration;
45 fn timeout_reconciliation(&self) -> Duration;
47 fn timeout_portfolio(&self) -> Duration;
49 fn timeout_disconnection(&self) -> Duration;
51 fn delay_post_stop(&self) -> Duration;
53 fn timeout_shutdown(&self) -> Duration;
55 fn cache(&self) -> Option<CacheConfig>;
57 fn msgbus(&self) -> Option<MessageBusConfig>;
59 fn data_engine(&self) -> Option<DataEngineConfig>;
61 fn risk_engine(&self) -> Option<RiskEngineConfig>;
63 fn exec_engine(&self) -> Option<ExecutionEngineConfig>;
65 fn portfolio(&self) -> Option<PortfolioConfig>;
67 fn streaming(&self) -> Option<StreamingConfig>;
69}
70
71#[derive(Debug, Clone)]
73pub struct KernelConfig {
74 pub environment: Environment,
76 pub trader_id: TraderId,
78 pub load_state: bool,
80 pub save_state: bool,
82 pub logging: LoggerConfig,
84 pub instance_id: Option<UUID4>,
86 pub timeout_connection: Duration,
88 pub timeout_reconciliation: Duration,
90 pub timeout_portfolio: Duration,
92 pub timeout_disconnection: Duration,
94 pub delay_post_stop: Duration,
96 pub timeout_shutdown: Duration,
98 pub cache: Option<CacheConfig>,
100 pub msgbus: Option<MessageBusConfig>,
102 pub data_engine: Option<DataEngineConfig>,
104 pub risk_engine: Option<RiskEngineConfig>,
106 pub exec_engine: Option<ExecutionEngineConfig>,
108 pub portfolio: Option<PortfolioConfig>,
110 pub streaming: Option<StreamingConfig>,
112}
113
114impl NautilusKernelConfig for KernelConfig {
115 fn environment(&self) -> Environment {
116 self.environment
117 }
118
119 fn trader_id(&self) -> TraderId {
120 self.trader_id
121 }
122
123 fn load_state(&self) -> bool {
124 self.load_state
125 }
126
127 fn save_state(&self) -> bool {
128 self.save_state
129 }
130
131 fn logging(&self) -> LoggerConfig {
132 self.logging.clone()
133 }
134
135 fn instance_id(&self) -> Option<UUID4> {
136 self.instance_id
137 }
138
139 fn timeout_connection(&self) -> Duration {
140 self.timeout_connection
141 }
142
143 fn timeout_reconciliation(&self) -> Duration {
144 self.timeout_reconciliation
145 }
146
147 fn timeout_portfolio(&self) -> Duration {
148 self.timeout_portfolio
149 }
150
151 fn timeout_disconnection(&self) -> Duration {
152 self.timeout_disconnection
153 }
154
155 fn delay_post_stop(&self) -> Duration {
156 self.delay_post_stop
157 }
158
159 fn timeout_shutdown(&self) -> Duration {
160 self.timeout_shutdown
161 }
162
163 fn cache(&self) -> Option<CacheConfig> {
164 self.cache.clone()
165 }
166
167 fn msgbus(&self) -> Option<MessageBusConfig> {
168 self.msgbus.clone()
169 }
170
171 fn data_engine(&self) -> Option<DataEngineConfig> {
172 self.data_engine.clone()
173 }
174
175 fn risk_engine(&self) -> Option<RiskEngineConfig> {
176 self.risk_engine.clone()
177 }
178
179 fn exec_engine(&self) -> Option<ExecutionEngineConfig> {
180 self.exec_engine.clone()
181 }
182
183 fn portfolio(&self) -> Option<PortfolioConfig> {
184 self.portfolio.clone()
185 }
186
187 fn streaming(&self) -> Option<StreamingConfig> {
188 self.streaming.clone()
189 }
190}
191
192impl Default for KernelConfig {
193 fn default() -> Self {
194 Self {
195 environment: Environment::Backtest,
196 trader_id: TraderId::default(),
197 load_state: false,
198 save_state: false,
199 logging: LoggerConfig::default(),
200 instance_id: None,
201 timeout_connection: Duration::from_secs(60),
202 timeout_reconciliation: Duration::from_secs(30),
203 timeout_portfolio: Duration::from_secs(10),
204 timeout_disconnection: Duration::from_secs(10),
205 delay_post_stop: Duration::from_secs(10),
206 timeout_shutdown: Duration::from_secs(5),
207 cache: None,
208 msgbus: None,
209 data_engine: None,
210 risk_engine: None,
211 exec_engine: None,
212 portfolio: None,
213 streaming: None,
214 }
215 }
216}
217
218#[derive(Debug, Clone)]
220pub enum RotationConfig {
221 Size {
223 max_size: u64,
225 },
226 Interval {
228 interval_ns: u64,
230 },
231 ScheduledDates {
233 interval_ns: u64,
235 schedule_ns: UnixNanos,
237 },
238 NoRotation,
240}
241
242#[derive(Debug, Clone)]
244pub struct StreamingConfig {
245 pub catalog_path: String,
247 pub fs_protocol: String,
249 pub flush_interval_ms: u64,
251 pub replace_existing: bool,
253 pub rotation_config: RotationConfig,
255}
256
257impl StreamingConfig {
258 #[must_use]
260 pub const fn new(
261 catalog_path: String,
262 fs_protocol: String,
263 flush_interval_ms: u64,
264 replace_existing: bool,
265 rotation_config: RotationConfig,
266 ) -> Self {
267 Self {
268 catalog_path,
269 fs_protocol,
270 flush_interval_ms,
271 replace_existing,
272 rotation_config,
273 }
274 }
275}