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 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.