nautilus_system/
kernel.rs
1#![allow(dead_code)]
18#![allow(unused_variables)]
19
20use std::{cell::RefCell, rc::Rc};
21
22use nautilus_common::{
23 cache::{Cache, CacheConfig, database::CacheDatabaseAdapter},
24 clock::{Clock, TestClock},
25 enums::Environment,
26};
27use nautilus_core::UUID4;
28use nautilus_data::engine::DataEngine;
29use nautilus_execution::engine::ExecutionEngine;
30use nautilus_model::identifiers::TraderId;
31use ustr::Ustr;
32
33use crate::config::NautilusKernelConfig;
34
35pub struct NautilusKernel {
37 pub name: Ustr,
38 pub instance_id: UUID4,
39 pub config: NautilusKernelConfig,
40 pub data_engine: DataEngine,
41 pub exec_engine: ExecutionEngine,
42 pub cache: Rc<RefCell<Cache>>,
43 pub clock: Rc<RefCell<dyn Clock>>,
44}
45
46impl NautilusKernel {
47 #[must_use]
48 pub fn new(name: Ustr, config: NautilusKernelConfig) -> Self {
49 let instance_id = config.instance_id.unwrap_or_default();
50 let clock = Self::initialize_clock(&config.environment);
51 let cache = Self::initialize_cache(config.trader_id, &instance_id, config.cache.clone());
52 let data_engine = DataEngine::new(clock.clone(), cache.clone(), config.data_engine.clone());
53 let exec_engine =
54 ExecutionEngine::new(clock.clone(), cache.clone(), config.exec_engine.clone());
55 Self {
56 name,
57 instance_id,
58 data_engine,
59 exec_engine,
60 config,
61 cache,
62 clock,
63 }
64 }
65
66 fn initialize_clock(environment: &Environment) -> Rc<RefCell<dyn Clock>> {
67 match environment {
68 Environment::Backtest => {
69 let test_clock = TestClock::new();
70 Rc::new(RefCell::new(test_clock))
71 }
72 Environment::Live | Environment::Sandbox => {
73 todo!("Initialize clock for Live and Sandbox environments")
74 }
75 }
76 }
77
78 fn initialize_cache(
79 trader_id: TraderId,
80 instance_id: &UUID4,
81 cache_config: Option<CacheConfig>,
82 ) -> Rc<RefCell<Cache>> {
83 let cache_config = cache_config.unwrap_or_default();
84 let cache_database: Option<Box<dyn CacheDatabaseAdapter>> =
85 if let Some(cache_database_config) = &cache_config.database {
86 todo!("initialize_cache_database")
87 } else {
88 None
89 };
90
91 let cache = Cache::new(Some(cache_config), cache_database);
92 Rc::new(RefCell::new(cache))
93 }
94
95 fn start(&self) {
96 todo!("implement start")
97 }
98
99 fn stop(&self) {
100 todo!("implement stop")
101 }
102
103 fn dispose(&self) {
104 todo!("implement dispose")
105 }
106
107 fn cancel_all_tasks(&self) {
108 todo!("implement cancel_all_tasks")
109 }
110
111 fn start_engines(&self) {
112 todo!("implement start_engines")
113 }
114
115 fn register_executor(&self) {
116 todo!("implement register_executor")
117 }
118
119 fn stop_engines(&self) {
120 todo!("implement stop_engines")
121 }
122
123 fn connect_clients(&self) {
124 todo!("implement connect_clients")
125 }
126
127 fn disconnect_clients(&self) {
128 todo!("implement disconnect_clients")
129 }
130
131 fn stop_clients(&self) {
132 todo!("implement stop_clients")
133 }
134
135 fn initialize_portfolio(&self) {
136 todo!("implement initialize_portfolio")
137 }
138
139 fn await_engines_connected(&self) {
140 todo!("implement await_engines_connected")
141 }
142
143 fn await_execution_reconciliation(&self) {
144 todo!("implement await_execution_reconciliation")
145 }
146
147 fn await_portfolio_initialized(&self) {
148 todo!("implement await_portfolio_initialized")
149 }
150
151 fn await_trader_residuals(&self) {
152 todo!("implement await_trader_residuals")
153 }
154
155 fn check_engines_connected(&self) {
156 todo!("implement check_engines_connected")
157 }
158
159 fn check_engines_disconnected(&self) {
160 todo!("implement check_engines_disconnected")
161 }
162
163 fn check_portfolio_initialized(&self) {
164 todo!("implement check_portfolio_initialized")
165 }
166
167 fn cancel_timers(&self) {
168 todo!("implement cancel_timers")
169 }
170
171 fn flush_writer(&self) {
172 todo!("implement flush_writer")
173 }
174}