Skip to main content

LiveNode

Struct LiveNode 

Source
pub struct LiveNode { /* private fields */ }
Expand description

High-level abstraction for a live Nautilus system node.

Provides a simplified interface for running live systems with automatic client management and lifecycle handling.

Implementations§

Source§

impl LiveNode

Source

pub fn builder( trader_id: TraderId, environment: Environment, ) -> Result<LiveNodeBuilder>

Creates a new LiveNodeBuilder for fluent configuration.

§Errors

Returns an error if the environment is invalid for live trading.

Source

pub fn build(name: String, config: Option<LiveNodeConfig>) -> Result<Self>

Creates a new LiveNode directly from a kernel name and optional configuration.

This is a convenience method for creating a live node with a pre-configured kernel configuration, bypassing the builder pattern. If no config is provided, a default configuration will be used.

§Errors

Returns an error if kernel construction fails.

Source

pub fn add_plugin(&mut self, config: PluginConfig) -> Result<()>

Loads and registers one plug-in instance.

§Errors

Returns an error because dynamic plug-in hosting lives in the host-side integration.

Source

pub fn handle(&self) -> LiveNodeHandle

Returns a thread-safe handle to control this node.

Source

pub async fn start(&mut self) -> Result<()>

Starts the live node without entering a select loop.

Connects clients, runs reconciliation, and starts the trader, but does not consume the runner or drive channel receivers, so channel traffic arriving after startup is never serviced. This is a building block for tests and embedding, not a lifecycle: use run or run_with_mode to run a node.

§Errors

Returns an error if startup fails.

Source

pub async fn stop(&mut self) -> Result<()>

Stop the live node.

This method stops the trader, waits for the configured grace period to allow residual events to be processed, then finalizes the shutdown sequence.

§Errors

Returns an error if shutdown fails.

Source

pub fn dispose(&mut self)

Disposes the live node kernel and releases resources.

Source

pub async fn run(&mut self) -> Result<()>

Run the live node with automatic shutdown handling.

This method starts the node, runs indefinitely, and handles graceful shutdown on interrupt signals.

§Thread Safety

The event loop runs directly on the current thread (not spawned) because the msgbus uses thread-local storage. Endpoints registered by the kernel are only accessible from the same thread.

§Shutdown Sequence
  1. Signal received (SIGINT, SIGTERM, or handle stop).
  2. Trader components stopped (triggers order cancellations, etc.).
  3. Event loop continues processing residual events for the configured grace period.
  4. Kernel finalized, clients disconnected, remaining events drained.
§Errors

Returns an error if the node fails to start or encounters a runtime error.

Source

pub async fn run_with_mode(&mut self, mode: NodeRunMode) -> Result<()>

Run the live node under the given mode.

NodeRunMode::Hosted leaves signal handling to the host application. Every other responsibility, including maintenance, reconciliation, external ingress, and the shutdown sequence, is identical across modes so that hosted and owned nodes cannot diverge.

§Errors

Returns an error if the node fails to start or encounters a runtime error.

Source

pub const fn has_pending_cache_database(&self) -> bool

Returns whether a cache database backing is configured but not yet installed.

Source

pub fn environment(&self) -> Environment

Gets the node’s environment.

Source

pub const fn kernel(&self) -> &NautilusKernel

Gets a reference to the underlying kernel.

Source

pub const fn kernel_mut(&mut self) -> &mut NautilusKernel

Gets an exclusive reference to the underlying kernel.

Source

pub fn trader_id(&self) -> TraderId

Gets the node’s trader ID.

Source

pub const fn instance_id(&self) -> UUID4

Gets the node’s instance ID.

Source

pub fn state(&self) -> NodeState

Returns the current node state.

Source

pub fn is_running(&self) -> bool

Checks if the live node is currently running.

Source

pub fn set_cache_database( &mut self, database: Box<dyn CacheDatabaseAdapter>, ) -> Result<()>

Sets the cache database adapter for persistence.

This allows setting a database adapter (e.g., PostgreSQL, Redis) after the node is built but before it starts running. The database adapter is used to persist cache data for recovery and state management.

§Errors

Returns an error if the node is already running.

Source

pub fn exec_manager(&self) -> &ExecutionManager

Returns the execution manager.

Source

pub fn exec_manager_mut(&mut self) -> &mut ExecutionManager

Returns a mutable reference to the execution manager.

Source

pub fn add_actor<T>(&mut self, actor: T) -> Result<()>
where T: DataActor + DataActorNative + Component + Actor + 'static,

Adds an actor to the trader.

This method provides a high-level interface for adding actors to the underlying trader without requiring direct access to the kernel. Actors should be added after the node is built but before starting the node.

§Errors

Returns an error if:

  • The trader is not in a valid state for adding components.
  • An actor with the same ID is already registered.
  • The node is currently running.
Source

pub fn add_actor_from_factory<F, T>(&mut self, factory: F) -> Result<()>
where F: FnOnce() -> Result<T>, T: DataActor + DataActorNative + Component + Actor + 'static,

Adds an actor to the live node using a factory function.

The factory function is called at registration time to create the actor, avoiding cloning issues with non-cloneable actor types.

§Errors

Returns an error if:

  • The node is currently running.
  • The factory function fails to create the actor.
  • The underlying trader registration fails.
Source

pub fn add_strategy<T>(&mut self, strategy: T) -> Result<()>

Adds a strategy to the trader.

Strategies are registered in both the component registry (for lifecycle management) and the actor registry (for data callbacks via msgbus).

§Errors

Returns an error if:

  • The node is currently running.
  • A strategy with the same ID is already registered.
  • The strategy configures one or more external order claims and the request repeats an instrument, or either tier already contains a requested claim.
  • The strategy configures one or more external order claims or an OMS type override, and the execution engine is already borrowed. A strategy configuring neither does not take the borrow and cannot fail this way.
Source

pub fn register_external_order_claims( &mut self, strategy_id: StrategyId, claims: &[InstrumentId], ) -> Result<()>

Registers external order claims on both live execution tiers.

The operation is synchronous and atomic across the reconciliation manager and execution engine. It can be called while the node is idle, after manual start returns, or after the node stops. It cannot be called while run or run_with_mode owns the node.

§Errors

Returns an error without changing either tier if the execution engine is already borrowed, the request repeats an instrument, or either tier already contains any requested claim.

Source

pub fn deregister_external_order_claims( &mut self, strategy_id: StrategyId, ) -> Result<()>

Deregisters all external order claims owned by strategy_id from both execution tiers.

Remove the strategy through the trader or controller first, then call this method before registering a successor. The operation is synchronous and can be called while the node is idle, after manual start returns, or after the node stops. It cannot be called while run or run_with_mode owns the node.

§Errors

Returns an error without changing either tier if the execution engine is already borrowed or the two tiers do not contain identical claim sets for the strategy.

Source

pub fn add_exec_algorithm<T>(&mut self, exec_algorithm: T) -> Result<()>

Adds an execution algorithm to the trader.

Execution algorithms are registered in both the component registry (for lifecycle management) and the actor registry (for data callbacks via msgbus).

§Errors

Returns an error if:

  • The node is currently running.
  • An execution algorithm with the same ID is already registered.

Trait Implementations§

Source§

impl Debug for LiveNode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.