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.
  • Data commands: subscribe/unsubscribe requests to data clients.
  • Data events: market data from adapters to the data engine.
  • Trading commands: order actions to execution clients.
  • Execution events: fills, order updates, and account state from execution clients to the execution engine.

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 unconditionally replaces the previous contents, 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