pub struct NautilusKernel {Show 16 fields
pub name: String,
pub instance_id: UUID4,
pub machine_id: String,
pub config: Box<dyn NautilusKernelConfig>,
pub cache: Rc<RefCell<Cache>>,
pub clock: Rc<RefCell<dyn Clock>>,
pub portfolio: Rc<RefCell<Portfolio>>,
pub log_guard: LogGuard,
pub data_engine: Rc<RefCell<DataEngine>>,
pub risk_engine: Rc<RefCell<RiskEngine>>,
pub exec_engine: Rc<RefCell<ExecutionEngine>>,
pub order_emulator: OrderEmulatorAdapter,
pub trader: Rc<RefCell<Trader>>,
pub ts_created: UnixNanos,
pub ts_started: Option<UnixNanos>,
pub ts_shutdown: Option<UnixNanos>,
/* private fields */
}Expand description
Core Nautilus system kernel.
Orchestrates data and execution engines, cache, clock, and messaging across environments.
Fields§
§name: StringThe kernel name (for logging and identification).
instance_id: UUID4The unique instance identifier for this kernel.
machine_id: StringThe machine identifier (hostname or similar).
config: Box<dyn NautilusKernelConfig>The kernel configuration.
cache: Rc<RefCell<Cache>>The shared in-memory cache.
clock: Rc<RefCell<dyn Clock>>The clock driving the kernel.
portfolio: Rc<RefCell<Portfolio>>The portfolio manager.
log_guard: LogGuardGuard for the logging subsystem (keeps logger thread alive).
data_engine: Rc<RefCell<DataEngine>>The data engine instance.
risk_engine: Rc<RefCell<RiskEngine>>The risk engine instance.
exec_engine: Rc<RefCell<ExecutionEngine>>The execution engine instance.
order_emulator: OrderEmulatorAdapterThe order emulator for handling emulated orders.
trader: Rc<RefCell<Trader>>The trader component (shared for Controller access).
ts_created: UnixNanosThe UNIX timestamp (nanoseconds) when the kernel was created.
ts_started: Option<UnixNanos>The UNIX timestamp (nanoseconds) when the kernel was last started.
ts_shutdown: Option<UnixNanos>The UNIX timestamp (nanoseconds) when the kernel was last shutdown.
Implementations§
Source§impl NautilusKernel
impl NautilusKernel
Sourcepub const fn builder(
name: String,
trader_id: TraderId,
environment: Environment,
) -> NautilusKernelBuilder
pub const fn builder( name: String, trader_id: TraderId, environment: Environment, ) -> NautilusKernelBuilder
Create a new NautilusKernelBuilder for fluent configuration.
Sourcepub fn new<T: NautilusKernelConfig + 'static>(
name: String,
config: T,
) -> Result<Self>
pub fn new<T: NautilusKernelConfig + 'static>( name: String, config: T, ) -> Result<Self>
Sourcepub fn new_with_cache_database<T: NautilusKernelConfig + 'static>(
name: String,
config: T,
cache_database: Option<Box<dyn CacheDatabaseAdapter>>,
) -> Result<Self>
pub fn new_with_cache_database<T: NautilusKernelConfig + 'static>( name: String, config: T, cache_database: Option<Box<dyn CacheDatabaseAdapter>>, ) -> Result<Self>
Create a new NautilusKernel instance with an injected cache database adapter.
The adapter is passed straight to [Cache::new] so the kernel can restore
generic cache state (including snapshot blobs anchored by the event store) from
the durable backing store on startup, without an external caller pre-seeding the
in-memory cache.
§Errors
Returns an error if the kernel fails to initialize.
Sourcepub fn new_with<T: NautilusKernelConfig + 'static>(
name: String,
config: T,
cache_database: Option<Box<dyn CacheDatabaseAdapter>>,
event_store_factory: Option<EventStoreFactory>,
) -> Result<Self>
pub fn new_with<T: NautilusKernelConfig + 'static>( name: String, config: T, cache_database: Option<Box<dyn CacheDatabaseAdapter>>, event_store_factory: Option<EventStoreFactory>, ) -> Result<Self>
Create a new NautilusKernel instance with optional cache database and event store
injections.
The cache adapter is passed to [Cache::new]; the event-store factory is invoked
with the kernel’s clock so the resulting KernelEventStore implementation shares
the same time source the kernel uses to stamp RunStarted/RunEnded and any
drop-seal fallback timestamp.
§Errors
Returns an error if the kernel fails to initialize or the event-store factory fails.
Sourcepub fn new_with_dependencies<T: NautilusKernelConfig + 'static>(
name: String,
config: T,
dependencies: NautilusKernelDependencies,
) -> Result<Self>
pub fn new_with_dependencies<T: NautilusKernelConfig + 'static>( name: String, config: T, dependencies: NautilusKernelDependencies, ) -> Result<Self>
Create a new NautilusKernel instance with construction-time dependencies.
§Errors
Returns an error if the kernel fails to initialize or an injected factory fails.
pub fn generate_timestamp_ns(&self) -> UnixNanos
Sourcepub fn environment(&self) -> Environment
pub fn environment(&self) -> Environment
Returns the kernel’s environment context (Backtest, Sandbox, Live).
Sourcepub fn machine_id(&self) -> &str
pub fn machine_id(&self) -> &str
Returns the kernel’s machine ID.
Sourcepub const fn instance_id(&self) -> UUID4
pub const fn instance_id(&self) -> UUID4
Returns the kernel’s instance ID.
Sourcepub fn delay_post_stop(&self) -> Duration
pub fn delay_post_stop(&self) -> Duration
Returns the delay after stopping the node to await residual events before final shutdown.
Sourcepub const fn ts_created(&self) -> UnixNanos
pub const fn ts_created(&self) -> UnixNanos
Returns the UNIX timestamp (ns) when the kernel was created.
Sourcepub const fn ts_started(&self) -> Option<UnixNanos>
pub const fn ts_started(&self) -> Option<UnixNanos>
Returns the UNIX timestamp (ns) when the kernel was last started.
Sourcepub const fn ts_shutdown(&self) -> Option<UnixNanos>
pub const fn ts_shutdown(&self) -> Option<UnixNanos>
Returns the UNIX timestamp (ns) when the kernel was last shutdown.
Sourcepub fn is_shutdown_requested(&self) -> bool
pub fn is_shutdown_requested(&self) -> bool
Returns true if shutdown has been requested.
Drains pending shutdown-on-error logs before checking the kernel flag.
Sourcepub fn reset_shutdown_flag(&self)
pub fn reset_shutdown_flag(&self)
Clears the shutdown flag.
Call this before starting a fresh run so a prior ShutdownSystem
command does not abort it.
Sourcepub fn shutdown_flag(&self) -> Rc<Cell<bool>>
pub fn shutdown_flag(&self) -> Rc<Cell<bool>>
Returns a shared handle to the shutdown flag for async runtimes that need to poll it outside the kernel’s direct borrow.
Sourcepub fn load_state(&self) -> bool
pub fn load_state(&self) -> bool
Returns whether the kernel has been configured to load state.
Sourcepub fn save_state(&self) -> bool
pub fn save_state(&self) -> bool
Returns whether the kernel has been configured to save state.
Sourcepub fn data_engine(&self) -> Ref<'_, DataEngine>
pub fn data_engine(&self) -> Ref<'_, DataEngine>
Returns the kernel’s data engine.
Sourcepub const fn risk_engine(&self) -> &Rc<RefCell<RiskEngine>>
pub const fn risk_engine(&self) -> &Rc<RefCell<RiskEngine>>
Returns the kernel’s risk engine.
Sourcepub const fn exec_engine(&self) -> &Rc<RefCell<ExecutionEngine>>
pub const fn exec_engine(&self) -> &Rc<RefCell<ExecutionEngine>>
Returns the kernel’s execution engine.
Sourcepub async fn start_async(&mut self)
pub async fn start_async(&mut self)
Starts the Nautilus system kernel asynchronously.
Sourcepub fn start_trader(&mut self)
pub fn start_trader(&mut self)
Starts the trader (strategies and actors).
This should be called after clients are connected and instruments are cached.
Sourcepub fn stop_trader(&mut self)
pub fn stop_trader(&mut self)
Stops the trader and its registered components.
This method initiates a graceful shutdown of trading components (strategies, actors) which may trigger residual events such as order cancellations. The caller should continue processing events after calling this method to handle these residual events.
Sourcepub async fn finalize_stop(&mut self)
pub async fn finalize_stop(&mut self)
Finalizes the kernel shutdown after the grace period.
This method should be called after the residual events grace period has elapsed and all remaining events have been processed. It disconnects clients and stops engines.
Sourcepub fn event_store(&self) -> Option<&dyn KernelEventStore>
pub fn event_store(&self) -> Option<&dyn KernelEventStore>
Returns the kernel-managed event-store integration, when one was injected.
Callers wire an implementation through
NautilusKernelBuilder::with_event_store;
without an injected adapter this returns None.
Sourcepub fn is_event_store_replay(&self) -> bool
pub fn is_event_store_replay(&self) -> bool
Returns whether the event-store integration is running an event-store replay start.
Sourcepub fn is_event_store_replay_configured(&self) -> bool
pub fn is_event_store_replay_configured(&self) -> bool
Returns whether the event-store integration is configured for an event-store replay start.
Sourcepub async fn connect_data_clients(&mut self)
pub async fn connect_data_clients(&mut self)
Connects data engine clients.
Data clients are connected first so that instruments are published and can be drained into the cache before execution clients connect.
Sourcepub async fn connect_exec_clients(&mut self)
pub async fn connect_exec_clients(&mut self)
Connects execution engine clients.
Must be called after data clients are connected and instrument events have been drained into the cache, so execution clients can load instruments.
Sourcepub async fn disconnect_clients(&mut self) -> Result<()>
pub async fn disconnect_clients(&mut self) -> Result<()>
Sourcepub fn check_engines_connected(&self) -> bool
pub fn check_engines_connected(&self) -> bool
Returns true if all engine clients are connected.
Sourcepub fn check_engines_disconnected(&self) -> bool
pub fn check_engines_disconnected(&self) -> bool
Returns true if all engine clients are disconnected.
Sourcepub fn data_client_connection_status(&self) -> Vec<(ClientId, bool)>
pub fn data_client_connection_status(&self) -> Vec<(ClientId, bool)>
Returns connection status for all data clients.
Sourcepub fn exec_client_connection_status(&self) -> Vec<(ClientId, bool)>
pub fn exec_client_connection_status(&self) -> Vec<(ClientId, bool)>
Returns connection status for all execution clients.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for NautilusKernel
impl !Send for NautilusKernel
impl !Sync for NautilusKernel
impl !UnwindSafe for NautilusKernel
impl Freeze for NautilusKernel
impl Unpin for NautilusKernel
impl UnsafeUnpin for NautilusKernel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more