Expand description
Async event loop runner for live and sandbox trading nodes.
AsyncRunner owns seven 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.
- System events: system notifications handled by the live node.
- System commands: control requests handled by the live node.
- Execution events: fills, order updates, and account state from execution clients to the execution engine.
- Trading commands: deferred order actions routed to their direct endpoint.
- 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
system and execution branches polled ahead of data branches. Within each
channel pair, events are polled before commands.
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_sendersoverwrites any existing TLS contents on the thread, 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
AsyncRunnerfrom another context. - Async
Time Event Sender - Asynchronous implementation of
TimeEventSenderfor live environments. - Async
Trading Command Sender - Asynchronous implementation of
TradingCommandSenderfor live environments.