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

Continuous inflight and open-order checks run on independent intervals. The shared maintenance timer in the select loop dispatches reconciliation at the minimum enabled interval. Each dispatch the handler checks which sub-checks are due based on elapsed nanoseconds and schedules their work. Continuous checks do not await venue HTTP in the select loop: open-order and position checks poll bulk venue report futures from the loop.

§Maintenance dispatcher

Six periodic tasks share a single coarse maintenance_timer:

  • reconciliation (inflight, open, position sub-checks)
  • purge closed orders
  • purge closed positions
  • purge account events
  • own-books audit
  • recent-fills cache prune

The runner wakes one timer per loop iteration regardless of how many maintenance tasks are configured. Each task tracks its own next_fire: Instant and the dispatcher fires the bodies whose deadline has passed, rescheduling next = now + interval (equivalent to MissedTickBehavior::Delay). Disabled tasks anchor on a far-future next that never trips.

The 100ms timer cadence is the effective floor for any maintenance interval. Configured intervals below 100ms (the config types allow inflight_check_interval_ms and own_books_audit_interval_secs smaller) get rounded up to the next tick. Real workloads do not run venue or cache maintenance below 100ms (defaults are seconds to minutes). Cadence drifts by at most one body duration per fire.

Re-exports§

pub use builder::LiveNodeBuilder;

Modules§

builder
Builder for constructing LiveNode instances.
config
Configuration types for live Nautilus system nodes.
plugin
Live-node plug-in support.

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.