Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Nautechsystems Nautilus trader LiveExecutionEngine Init

From Leeroopedia


Field Value
sources https://github.com/nautechsystems/nautilus_trader, https://nautilustrader.io/docs/
domains algorithmic trading, execution management, state reconciliation, fault tolerance
last_updated 2026-02-10 12:00 GMT

Overview

Concrete tool for initializing the live execution engine with reconciliation and retry capabilities provided by NautilusTrader.

Description

The LiveExecutionEngine extends the base ExecutionEngine with asynchronous queue processing, startup and continuous reconciliation, in-flight order monitoring, and cache purging for long-running systems. During initialisation it:

  • Creates async command and event queues with configurable size (qsize, default 100,000).
  • Sets up reconciliation state tracking: retry counters per order, last-query timestamps, local activity timestamps, recent fills cache, and a startup reconciliation event gate.
  • Instantiates ThrottledEnqueuer objects for rate-controlled queue insertion.
  • Creates placeholders for async tasks: command queue processing, event queue processing, reconciliation loop, own-books audit, and cache purge tasks.
  • Reads and stores all reconciliation configuration parameters from LiveExecEngineConfig (reconciliation toggle, lookback window, instrument filters, in-flight check intervals, open order check intervals, position check intervals, purge schedules).
  • Registers message bus endpoints for receiving execution mass status reports, order status reports, fill reports, and position status reports.

The companion RetryManager class provides generic async retry logic with exponential backoff and jitter. It is used by execution clients for order submission, modification, and cancellation retries. The RetryManagerPool manages a pool of retry managers for concurrent operations.

Usage

The LiveExecutionEngine is created automatically by the NautilusKernel during node construction. Operators configure it through LiveExecEngineConfig in the TradingNodeConfig. The RetryManager is used internally by exchange adapter execution clients.

Code Reference

Source Location

Item Path
LiveExecutionEngine class nautilus_trader/live/execution_engine.py lines 96-247
LiveExecEngineConfig nautilus_trader/live/config.py lines 76-226
RetryManager class nautilus_trader/live/retry.py lines 65-240
RetryManagerPool class nautilus_trader/live/retry.py lines 242-371

Signature

class LiveExecutionEngine(ExecutionEngine):
    def __init__(
        self,
        loop: asyncio.AbstractEventLoop,
        msgbus: MessageBus,
        cache: Cache,
        clock: LiveClock,
        config: LiveExecEngineConfig | None = None,
    ) -> None: ...
class RetryManager[T]:
    def __init__(
        self,
        max_retries: int,
        delay_initial_ms: int,
        delay_max_ms: int,
        backoff_factor: int,
        logger: Logger,
        exc_types: tuple[type[BaseException], ...],
        retry_check: Callable[[BaseException], bool] | None = None,
        error_logger: Callable[[str, BaseException | None], None] | None = None,
    ) -> None: ...

    async def run(
        self,
        name: str,
        details: list[object] | None,
        func: Callable[..., Awaitable[T]],
        *args,
        **kwargs,
    ) -> T | None: ...

Import

from nautilus_trader.live.execution_engine import LiveExecutionEngine
from nautilus_trader.config import LiveExecEngineConfig
from nautilus_trader.live.retry import RetryManager
from nautilus_trader.live.retry import RetryManagerPool

I/O Contract

LiveExecutionEngine Inputs

Parameter Type Required Description
loop asyncio.AbstractEventLoop Yes The event loop for async queue processing and reconciliation tasks.
msgbus MessageBus Yes Message bus for command/event routing.
cache Cache Yes Cache for order, position, and instrument lookups.
clock LiveClock Yes Clock for timestamps and interval scheduling.
config None No Configuration. Defaults to LiveExecEngineConfig().

LiveExecEngineConfig Key Fields

Field Type Default Description
reconciliation bool True If execution reconciliation is active at startup.
reconciliation_lookback_mins None None Max lookback minutes; None or 0 uses venue maximum.
inflight_check_interval_ms NonNegativeInt 2_000 Interval between in-flight order checks.
inflight_check_threshold_ms NonNegativeInt 5_000 Time threshold before checking an in-flight order.
open_check_interval_secs None None Interval for open order polling. None disables.
position_check_interval_secs None None Interval for position discrepancy checks. None disables.
generate_missing_orders bool True Generate MARKET orders to reconcile position discrepancies.
filter_unclaimed_external_orders bool False Drop order events with EXTERNAL strategy ID.
qsize PositiveInt 100_000 Queue size for command and event buffers.
graceful_shutdown_on_exception bool False Perform graceful shutdown on unexpected queue processing exceptions.

RetryManager Inputs

Parameter Type Required Description
max_retries int Yes Maximum retry attempts before failure.
delay_initial_ms int Yes Initial delay in milliseconds.
delay_max_ms int Yes Maximum delay for exponential backoff.
backoff_factor int Yes Exponential backoff multiplier.
logger Logger Yes Logger for retry warnings and errors.
exc_types tuple[type[BaseException], ...] Yes Exception types that trigger retry.
retry_check None No Additional check function; return False to abort retry.

Outputs / Key Attributes

Attribute Type Description
reconciliation_lookback_mins int Configured lookback window for reconciliation.
inflight_check_interval_ms int Configured in-flight check interval.
open_check_interval_secs None Configured open order check interval.
position_check_interval_secs None Configured position check interval.

Usage Examples

Configuring Reconciliation via TradingNodeConfig

from nautilus_trader.config import TradingNodeConfig
from nautilus_trader.config import LiveExecEngineConfig

config = TradingNodeConfig(
    trader_id="TRADER-001",
    exec_engine=LiveExecEngineConfig(
        reconciliation=True,
        reconciliation_lookback_mins=30,
        inflight_check_interval_ms=2_000,
        inflight_check_threshold_ms=5_000,
        open_check_interval_secs=10.0,
        position_check_interval_secs=30.0,
    ),
)

Disabling Reconciliation (Not Recommended for Production)

from nautilus_trader.config import TradingNodeConfig
from nautilus_trader.config import LiveExecEngineConfig

config = TradingNodeConfig(
    trader_id="TRADER-001",
    exec_engine=LiveExecEngineConfig(
        reconciliation=False,
    ),
)

Configuring Cache Purging for HFT

from nautilus_trader.config import TradingNodeConfig
from nautilus_trader.config import LiveExecEngineConfig

config = TradingNodeConfig(
    trader_id="TRADER-001",
    exec_engine=LiveExecEngineConfig(
        purge_closed_orders_interval_mins=10,
        purge_closed_orders_buffer_mins=60,
        purge_closed_positions_interval_mins=15,
        purge_closed_positions_buffer_mins=60,
    ),
)

Using RetryManager in a Custom Client

from nautilus_trader.live.retry import RetryManager

retry_manager = RetryManager(
    max_retries=3,
    delay_initial_ms=500,
    delay_max_ms=2_000,
    backoff_factor=2,
    logger=self._log,
    exc_types=(RuntimeError, ConnectionError),
)

result = await retry_manager.run(
    name="submit_order",
    details=[order.client_order_id],
    func=self._http_client.submit_order,
    order_params,
)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment