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.

Heuristic:Nautechsystems Nautilus trader Strategy On Start Initialization

From Leeroopedia




Knowledge Sources
Domains Debugging, Strategy_Development
Last Updated 2026-02-10 08:30 GMT

Overview

Best practice for strategy initialization: always override `on_start()` to subscribe to data and request initial state, as the framework warns when this handler is not implemented.

Description

The `Strategy.on_start()` method is the designated entry point for strategy initialization logic that depends on the trading system being fully operational. This includes subscribing to market data (bars, trade ticks, quote ticks), requesting historical data, setting up indicators, and initializing any state required for trading decisions. The framework emits a warning log if this method is not overridden, signaling that the strategy likely has a missing implementation.

This method is called after the strategy has been registered with the trader and all system components (data engine, execution engine, risk engine) are available.

Usage

Use this heuristic when:

  • Developing a new trading strategy
  • Debugging a strategy that is not receiving data events
  • Seeing warning messages about `on_start` not being overridden

The Insight (Rule of Thumb)

  • Action: Always override `on_start()` in your strategy subclass.
  • Must do in on_start:
    • Subscribe to market data (e.g., `self.subscribe_bars()`, `self.subscribe_trade_ticks()`)
    • Request any historical data needed for indicator warm-up
    • Initialize indicators and register them
  • Must NOT do in on_start:
    • Submit orders (the market may not be ready; use `on_bar()` or `on_trade_tick()` instead)
    • Block with synchronous I/O (this runs in the event loop)
  • Trade-off: Forgetting to override `on_start()` means no data subscriptions, so the strategy will never receive any market events and will sit idle.

Reasoning

NautilusTrader uses an event-driven architecture. Strategies do not poll for data; they receive callbacks when subscribed data arrives. If `on_start()` is not overridden and no subscriptions are made, the strategy will simply never receive any events. The framework warning exists specifically to catch this common mistake, which would otherwise be very difficult to debug (the strategy would appear to "do nothing" without any errors).

The `on_start()`/`on_stop()` lifecycle pattern also ensures clean setup and teardown. Data subscriptions made in `on_start()` are automatically cleaned up when the strategy is stopped or removed.

Code Evidence

Default on_start warning from `trading/strategy.pyx:222-228`:

cpdef void on_start(self):
    # Should override in subclass
    self.log.warning(
        "The `Strategy.on_start` handler was called when not overridden. "
        "It's expected that any actions required when starting the strategy "
        "occur here, such as subscribing/requesting data",
    )

on_start is called during strategy startup from `trading/strategy.pyx:402`:

self.on_start()

Related Pages

Page Connections

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