Skip to main content

Module node

Module node 

Source
Expand description

Live trading node built on a single-threaded tokio event loop.

LiveNode::run() drives the system through a tokio::select! loop that multiplexes data events, execution events, trading commands, timers, and periodic maintenance tasks (reconciliation, purge, prune, audit).

§Threading model

The core types (ExecutionManager, ExecutionEngine, Cache) use Rc<RefCell<..>> and are !Send. All access happens on the same thread. The select! macro runs one branch to completion (including inner awaits) before polling the next, so RefCell borrows held across .await points within a single branch cannot conflict with borrows in other branches.

§Startup sequencing

Startup connects clients in two phases so that instruments are in the cache before execution clients read them:

  1. Connect data clients (instruments arrive as buffered DataEvents).
  2. Flush all pending data events and commands into the cache via flush_pending_data, which loops try_recv on the channel receivers until no items remain.
  3. Connect execution clients (load_instruments_from_cache now finds populated instruments).
  4. Drain remaining events, then run reconciliation.

Both run() (integrated event loop) and start() (manual lifecycle) follow this sequence.

§Reconciliation

Three sub-checks run on independent intervals: inflight orders, open order consistency, and position consistency. A single reconciliation timer fires at the minimum enabled interval. Each tick, the handler checks which sub-checks are due based on elapsed nanoseconds and runs them in sequence. The open order and position checks query venues via async HTTP calls, blocking the select loop for the duration of each query.

Structs§

LiveNode
High-level abstraction for a live Nautilus system node.
LiveNodeHandle
A thread-safe handle to control a LiveNode from other threads.

Enums§

NodeState
Lifecycle state of the LiveNode runner.