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 atokio::select!loop internally. - Integrated: call
AsyncRunner::take_channelsto extract the receivers and run theselect!loop directly insideLiveNode::run, where it is interleaved with startup, reconciliation, and shutdown phases.
§Invariants
bind_sendersmust 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 theRefCell-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_sendersunconditionally replaces the previous contents, so the last caller wins.
Structs§
- Async
Data Command Sender - Asynchronous implementation of
DataCommandSenderfor live environments. - Async
Runner - Async
Runner Channels - Channel receivers for the async event loop.
- Async
Runner Handle - Handle for stopping the AsyncRunner from another context.
- Async
Time Event Sender - Asynchronous implementation of
TimeEventSenderfor live environments. - Async
Trading Command Sender - Asynchronous implementation of
TradingCommandSenderfor live environments.