{"record":{"id":"c455b77fec343a81","repo":"nautechsystems/nautilus_trader","slug":"strategy-not-registered-trader-id-is-not-set","errorCode":null,"errorMessage":"Strategy not registered: trader_id is not set","messagePattern":"Strategy not registered: trader_id is not set","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/trading/src/strategy/mod.rs","lineNumber":2438,"sourceCode":"}\n\nfn send_exec_command(command: TradingCommand) {\n    log_cmd_send(&command);\n    let endpoint = MessagingSwitchboard::exec_engine_queue_execute();\n    msgbus::send_trading_command(endpoint, command);\n}\n\nfn log_cmd_send(command: &TradingCommand) {\n    if let Some(id) = command.strategy_id() {\n        log::info!(\"{id} {CMD}{SEND} {command}\");\n    } else {\n        log::info!(\"{CMD}{SEND} {command}\");\n    }\n}\n\nfn registered_trader_id(core: &StrategyCore) -> anyhow::Result<TraderId> {\n    core.trader_id()\n        .ok_or_else(|| anyhow::anyhow!(\"Strategy not registered: trader_id is not set\"))\n}\n\nfn registered_strategy_id(core: &StrategyCore) -> anyhow::Result<StrategyId> {\n    core.strategy_id()\n        .ok_or_else(|| anyhow::anyhow!(\"Strategy not registered: strategy_id is not set\"))\n}\n\nfn required_account_id(order: &OrderAny, operation: &str) -> anyhow::Result<AccountId> {\n    order.account_id().ok_or_else(|| {\n        anyhow::anyhow!(\n            \"Cannot generate {operation} event for {}: account_id is not set\",\n            order.client_order_id()\n        )\n    })\n}\n\n#[cfg(test)]\nmod tests {","sourceCodeStart":2420,"sourceCodeEnd":2456,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/trading/src/strategy/mod.rs#L2420-L2456","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Register the strategy with the trading node before calling any order methods (trader.add_strategy).","Verify node.start()/run() completed registration (check logs for strategy registration).","In tests, use the test harness/fixtures that register the strategy rather than raw construction.","Check that an earlier registration error did not leave trader_id unset."],"exampleFix":"// before\nlet mut strategy = MyStrategy::new(config);\nstrategy.buy(...)?; // not registered\n// after\nlet mut strategy = MyStrategy::new(config);\ntrader.add_strategy(strategy)?;\nstrategy.buy(...)?;","handlingStrategy":"validation","validationCode":"if strategy.core().trader_id().is_none() { return Err(\"strategy not registered with trader\".into()); }","typeGuard":null,"tryCatchPattern":"match strategy.submit_order(&order) {\n    Err(e) if e.to_string().contains(\"not registered\") => return Err(anyhow!(\"register strategy with trader before trading: {e}\")),\n    other => other?,\n}","preventionTips":["Always add strategies via trader.add_strategy before use","Never call order methods on manually constructed strategies","Assert trader_id is set in startup checks"],"tags":["rust","strategy-registration","lifecycle"],"backgroundTag":"missing-required-config-field","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}