Skip to main content

Module runner

Module runner 

Source
Expand description

Async event loop runner for live and sandbox trading nodes.

AsyncRunner owns five tokio mpsc channel pairs plus a shutdown signal channel. Construction creates the channels without side effects. The sender halves are placed into thread-local storage via AsyncRunner::bind_senders so that adapters and engine components can resolve them through the get_*_sender() accessors in nautilus_common::runner and nautilus_common::live::runner.

Channel pairs:

  • Time events: timer callbacks dispatched by the clock.
  • Execution events: fills, order updates, and account state from execution clients to the execution engine.
  • Trading commands: order actions to execution clients.
  • Data events: market data from adapters to the data engine.
  • Data commands: subscribe/unsubscribe requests to data clients.

Both AsyncRunner::run and LiveNode::run use a biased; select with exec branches polled ahead of data branches, so a strategy action (cancel, submit) is not delayed behind a market-data backlog when the select polls receivers each iteration. The two loops use slightly different cmd/evt sub-orders because LiveNode::run also folds in the maintenance timer and signal handling that AsyncRunner::run does not see; check each select! block for the exact order at that site.

The runner can drive the event loop in two ways:

  • Standalone: call AsyncRunner::run, which binds senders and enters a tokio::select! loop internally.
  • Integrated: call AsyncRunner::take_channels to extract the receivers and run the select! loop directly inside LiveNode::run, where it is interleaved with startup, reconciliation, and shutdown phases.

§Invariants

  • bind_senders must be called before any code that reads from TLS. This includes adapter constructors, clock initialization, and execution client start methods. Every path from construction to the event loop must bind before the first TLS read.
  • The event loop and all TLS consumers must execute on the same thread. Senders are cloneable and Send, but the RefCell-backed TLS slots are not accessible from other threads.
  • Only one runner at a time should own the TLS slots on a given thread. bind_senders overwrites any existing TLS contents on the thread, so the last caller wins.

Structs§

AsyncDataCommandSender
Asynchronous implementation of DataCommandSender for live environments.
AsyncRunner
AsyncRunnerChannels
Channel receivers for the async event loop.
AsyncRunnerHandle
Handle for stopping the AsyncRunner from another context.
AsyncTimeEventSender
Asynchronous implementation of TimeEventSender for live environments.
AsyncTradingCommandSender
Asynchronous implementation of TradingCommandSender for live environments.

Traits§

Runner