Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Nautechsystems Nautilus trader StrategyConfig Definition

From Leeroopedia
Revision as of 16:01, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Nautechsystems_Nautilus_trader_StrategyConfig_Definition.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Field Value
sources https://github.com/nautechsystems/nautilus_trader , https://nautilustrader.io/docs/
domains algorithmic trading, strategy configuration, NautilusTrader
last_updated 2026-02-10 12:00 GMT

Overview

Concrete tool for defining immutable, serializable trading strategy configurations provided by NautilusTrader.

Description

StrategyConfig is a frozen msgspec struct that inherits from NautilusConfig. It serves as the base model for all trading strategy configurations in NautilusTrader. Because it uses frozen=True, all instances are immutable after construction -- any attempt to modify a field after creation raises an error. The kw_only=True constraint ensures that all fields must be specified by keyword, preventing positional argument mistakes.

The class provides sensible defaults for every field, so a minimal configuration requires no arguments at all. Users who need custom strategies subclass StrategyConfig and add their own fields, inheriting all the base fields and the frozen/keyword-only guarantees.

Usage

Import and use StrategyConfig when:

  • Creating a new trading strategy class that requires configuration parameters.
  • Subclassing to add strategy-specific parameters (e.g., indicator periods, thresholds).
  • Serializing strategy parameters for storage, logging, or cross-process communication.

Code Reference

Source Location

nautilus_trader/trading/config.py, lines 33-100.

Signature

class StrategyConfig(NautilusConfig, kw_only=True, frozen=True):
    strategy_id: StrategyId | None = None
    order_id_tag: str | None = None
    use_uuid_client_order_ids: bool = False
    use_hyphens_in_client_order_ids: bool = True
    oms_type: str | None = None
    external_order_claims: list[InstrumentId] | None = None
    manage_contingent_orders: bool = False
    manage_gtd_expiry: bool = False
    manage_stop: bool = False
    market_exit_interval_ms: PositiveInt = 100
    market_exit_max_attempts: PositiveInt = 100
    market_exit_time_in_force: TimeInForce = TimeInForce.GTC
    market_exit_reduce_only: bool = True
    log_events: bool = True
    log_commands: bool = True
    log_rejected_due_post_only_as_warning: bool = True

Import

from nautilus_trader.trading.config import StrategyConfig

I/O Contract

Inputs

Parameter Type Required Description
strategy_id StrategyId or None No Unique ID for the strategy. If None, the class name is used.
order_id_tag str or None No Unique order ID tag. Must be unique among running strategies per trader.
use_uuid_client_order_ids bool No Whether to use UUID4 values for client order IDs. Default False.
use_hyphens_in_client_order_ids bool No Whether to include hyphens in generated client order IDs. Default True.
oms_type str or None No Order management system type (e.g., "HEDGING", "NETTING"). Default None (venue native).
external_order_claims list[InstrumentId] or None No Instrument IDs for which external orders are claimed by this strategy.
manage_contingent_orders bool No Auto-manage OTO/OCO/OUO contingent orders. Default False.
manage_gtd_expiry bool No Auto-manage GTD time-in-force expirations. Default False.
manage_stop bool No Auto-perform market exit on stop. Default False.
market_exit_interval_ms PositiveInt No Check interval (ms) during market exit. Default 100.
market_exit_max_attempts PositiveInt No Max attempts during market exit. Default 100.
market_exit_time_in_force TimeInForce No Time in force for closing orders during market exit. Default GTC.
market_exit_reduce_only bool No Whether closing orders are reduce-only. Default True.
log_events bool No Whether to log events. Default True.
log_commands bool No Whether to log commands. Default True.
log_rejected_due_post_only_as_warning bool No Log post-only rejections as warnings. Default True.

Outputs

Output Type Description
StrategyConfig instance StrategyConfig A frozen, immutable configuration object containing all strategy parameters.

Usage Examples

Minimal configuration (all defaults):

from nautilus_trader.trading.config import StrategyConfig

config = StrategyConfig()

Custom configuration with specific OMS type and order tagging:

from nautilus_trader.trading.config import StrategyConfig

config = StrategyConfig(
    strategy_id="MyStrategy-001",
    order_id_tag="001",
    oms_type="HEDGING",
    manage_contingent_orders=True,
    manage_gtd_expiry=True,
)

Subclassing for a custom strategy:

from nautilus_trader.trading.config import StrategyConfig


class EMACrossConfig(StrategyConfig, frozen=True):
    instrument_id: str = "AAPL.XNAS"
    fast_ema_period: int = 10
    slow_ema_period: int = 20
    trade_size: str = "100"


config = EMACrossConfig(
    order_id_tag="EMA",
    oms_type="HEDGING",
    fast_ema_period=12,
    slow_ema_period=26,
)

Configuration with automatic market exit on stop:

from nautilus_trader.trading.config import StrategyConfig

config = StrategyConfig(
    manage_stop=True,
    market_exit_interval_ms=200,
    market_exit_max_attempts=50,
    market_exit_reduce_only=True,
)

Related Pages

Page Connections

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