17
17
#![ allow( dead_code) ]
18
18
#![ allow( unused_variables) ]
19
19
20
- use std:: collections:: HashMap ;
20
+ use std:: { cell :: RefCell , collections:: HashMap , rc :: Rc } ;
21
21
22
- use nautilus_common:: enums:: Environment ;
22
+ use nautilus_common:: { clock :: LiveClock , component :: Component , enums:: Environment } ;
23
23
use nautilus_core:: UUID4 ;
24
24
use nautilus_model:: identifiers:: TraderId ;
25
25
use nautilus_system:: {
@@ -28,17 +28,15 @@ use nautilus_system::{
28
28
kernel:: NautilusKernel ,
29
29
} ;
30
30
31
- use crate :: {
32
- config:: LiveNodeConfig ,
33
- runner:: { AsyncRunner , Runner } ,
34
- } ;
31
+ use crate :: { config:: LiveNodeConfig , runner:: AsyncRunner } ;
35
32
36
33
/// High-level abstraction for a live Nautilus system node.
37
34
///
38
35
/// Provides a simplified interface for running live systems
39
36
/// with automatic client management and lifecycle handling.
40
37
#[ derive( Debug ) ]
41
38
pub struct LiveNode {
39
+ clock : Rc < RefCell < LiveClock > > ,
42
40
kernel : NautilusKernel ,
43
41
runner : AsyncRunner ,
44
42
config : LiveNodeConfig ,
@@ -80,12 +78,14 @@ impl LiveNode {
80
78
}
81
79
}
82
80
81
+ let clock = Rc :: new ( RefCell :: new ( LiveClock :: new ( ) ) ) ;
83
82
let kernel = NautilusKernel :: new ( name, config. clone ( ) ) ?;
84
- let runner = AsyncRunner :: new ( ) ;
83
+ let runner = AsyncRunner :: new ( clock . clone ( ) ) ;
85
84
86
85
log:: info!( "LiveNode built successfully with kernel config" ) ;
87
86
88
87
Ok ( Self {
88
+ clock,
89
89
kernel,
90
90
runner,
91
91
config,
@@ -182,6 +182,28 @@ impl LiveNode {
182
182
pub const fn is_running ( & self ) -> bool {
183
183
self . is_running
184
184
}
185
+
186
+ /// Adds an actor to the trader.
187
+ ///
188
+ /// This method provides a high-level interface for adding actors to the underlying
189
+ /// trader without requiring direct access to the kernel. Actors should be added
190
+ /// after the node is built but before starting the node.
191
+ ///
192
+ /// # Errors
193
+ ///
194
+ /// Returns an error if:
195
+ /// - The trader is not in a valid state for adding components.
196
+ /// - An actor with the same ID is already registered.
197
+ /// - The node is currently running.
198
+ pub fn add_actor ( & mut self , actor : Box < dyn Component > ) -> anyhow:: Result < ( ) > {
199
+ if self . is_running {
200
+ anyhow:: bail!(
201
+ "Cannot add actor while node is running. Add actors before calling start()."
202
+ ) ;
203
+ }
204
+
205
+ self . kernel . trader . add_actor ( actor)
206
+ }
185
207
}
186
208
187
209
/// Builder for constructing a [`LiveNode`] with a fluent API.
@@ -357,10 +379,12 @@ impl LiveNodeBuilder {
357
379
log:: info!( "LiveNode built successfully" ) ;
358
380
359
381
// Create kernel directly with the config
382
+ let clock = Rc :: new ( RefCell :: new ( LiveClock :: new ( ) ) ) ;
360
383
let kernel = NautilusKernel :: new ( "LiveNode" . to_string ( ) , self . config . clone ( ) ) ?;
361
- let runner = AsyncRunner :: new ( ) ;
384
+ let runner = AsyncRunner :: new ( clock . clone ( ) ) ;
362
385
363
386
Ok ( LiveNode {
387
+ clock,
364
388
kernel,
365
389
runner,
366
390
config : self . config ,
0 commit comments