nautechsystems/nautilus_trader · error · anyhow::Error

Strategy not registered: trader_id is not set

Error message

Strategy not registered: trader_id is not set

What it means

Raised by `registered_trader_id` when `StrategyCore.trader_id()` is None, meaning the strategy was never registered with a trading node (or registration failed), so command routing cannot determine the TraderId. Called before building submit/modify/cancel commands.

Source

Thrown at crates/trading/src/strategy/mod.rs:2438

}

fn send_exec_command(command: TradingCommand) {
    log_cmd_send(&command);
    let endpoint = MessagingSwitchboard::exec_engine_queue_execute();
    msgbus::send_trading_command(endpoint, command);
}

fn log_cmd_send(command: &TradingCommand) {
    if let Some(id) = command.strategy_id() {
        log::info!("{id} {CMD}{SEND} {command}");
    } else {
        log::info!("{CMD}{SEND} {command}");
    }
}

fn registered_trader_id(core: &StrategyCore) -> anyhow::Result<TraderId> {
    core.trader_id()
        .ok_or_else(|| anyhow::anyhow!("Strategy not registered: trader_id is not set"))
}

fn registered_strategy_id(core: &StrategyCore) -> anyhow::Result<StrategyId> {
    core.strategy_id()
        .ok_or_else(|| anyhow::anyhow!("Strategy not registered: strategy_id is not set"))
}

fn required_account_id(order: &OrderAny, operation: &str) -> anyhow::Result<AccountId> {
    order.account_id().ok_or_else(|| {
        anyhow::anyhow!(
            "Cannot generate {operation} event for {}: account_id is not set",
            order.client_order_id()
        )
    })
}

#[cfg(test)]
mod tests {

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Register the strategy with the trading node before calling any order methods (trader.add_strategy).
  2. Verify node.start()/run() completed registration (check logs for strategy registration).
  3. In tests, use the test harness/fixtures that register the strategy rather than raw construction.
  4. Check that an earlier registration error did not leave trader_id unset.

Example fix

// before
let mut strategy = MyStrategy::new(config);
strategy.buy(...)?; // not registered
// after
let mut strategy = MyStrategy::new(config);
trader.add_strategy(strategy)?;
strategy.buy(...)?;
Defensive patterns

Strategy: validation

Validate before calling

if strategy.core().trader_id().is_none() { return Err("strategy not registered with trader".into()); }

Try / catch

match strategy.submit_order(&order) {
    Err(e) if e.to_string().contains("not registered") => return Err(anyhow!("register strategy with trader before trading: {e}")),
    other => other?,
}

Prevention

When it happens

Trigger: Calling submit_order_list, modify_order(s), cancel_order(s) or cancel_all_orders on a strategy instance that was not registered via the trader's `trader.add_strategy(...)` / builder registration.

Common situations: Instantiating a strategy manually in a test or script and calling its order methods directly, forgetting to add the strategy to the trader before start, or registration erroring silently earlier.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/c455b77fec343a81. Report an issue: GitHub.