{"record":{"id":"f4ad418a89dc6aad","repo":"nautechsystems/nautilus_trader","slug":"strategy-strategy-id-is-not-registered-with-a-tr","errorCode":null,"errorMessage":"Strategy {strategy_id} is not registered with a trader","messagePattern":"Strategy (.+?) is not registered with a trader","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/trading/src/strategy/mod.rs","lineNumber":135,"sourceCode":"    /// External orders, fills, and materialized reconciliation activity for matching instrument\n    /// IDs are assigned to the strategy. Passing an empty vector releases every claim owned by the\n    /// strategy. Existing cached orders keep their assigned strategy ID.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the strategy is not registered, the cache is already borrowed, an\n    /// instrument is repeated, or an instrument is claimed by another strategy.\n    fn set_external_order_instrument_ids(\n        &mut self,\n        instrument_ids: Vec<InstrumentId>,\n    ) -> anyhow::Result<()>\n    where\n        Self: StrategyNative,\n    {\n        let core = StrategyNative::strategy_core_mut(self);\n        let strategy_id = registered_strategy_id(core)?;\n        if !core.actor.is_registered() {\n            anyhow::bail!(\"Strategy {strategy_id} is not registered with a trader\");\n        }\n        let cache = core.cache_rc();\n        cache\n            .try_borrow_mut()\n            .map_err(|e| anyhow::anyhow!(\"Cannot set external order claims: {e}\"))?\n            .set_external_order_claims(strategy_id, &instrument_ids)?;\n        core.config.external_order_instrument_ids = Some(instrument_ids);\n        Ok(())\n    }\n\n    /// Returns the runtime strategy ID, when configured or registered.\n    fn strategy_id(&self) -> Option<StrategyId>\n    where\n        Self: StrategyNative,\n    {\n        StrategyNative::strategy_core(self).strategy_id()\n    }\n","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/trading/src/strategy/mod.rs#L117-L153","documentation":"set_external_order_instrument_ids requires the strategy to be registered with a running trader. The call bails when the underlying actor core reports is_registered() == false, because external order claims are recorded in the trader's cache under the registered strategy ID.","triggerScenarios":"Calling set_external_order_instrument_ids before the strategy has been added to a trading node and the node/trader started — e.g. in __init__, on_init, or on a standalone strategy instance never attached to a trader.","commonSituations":"Calling the API in on_init instead of on_start; constructing a Strategy in isolation (unit test or script) without a BacktestEngine/TradingNode; node startup ordering where config code runs before registration.","solutions":["Move the set_external_order_instrument_ids call into on_start, after registration is guaranteed.","Ensure the strategy is added to a TradingNode/BacktestEngine and the node is started before using the API.","Guard the call with a registration check and defer it (e.g. schedule) until the strategy is registered."],"exampleFix":"// before\nclass MyStrategy(Strategy):\n    def on_init(self, event):\n        self.set_external_order_instrument_ids([instrument_id])\n\n// after\nclass MyStrategy(Strategy):\n    def on_start(self):\n        self.set_external_order_instrument_ids([instrument_id])","handlingStrategy":"validation","validationCode":"if not strategy.is_registered:\n    raise RuntimeError(\"call set_external_order_instrument_ids only after the trader registers the strategy (on_start)\")","typeGuard":"def can_set_external_claims(strategy) -> bool:\n    return bool(getattr(strategy, \"is_registered\", False))","tryCatchPattern":"try:\n    self.set_external_order_instrument_ids(ids)\nexcept RuntimeError as e:\n    if \"not registered with a trader\" in str(e):\n        self.log.warning(\"deferred external claims setup: strategy not yet registered\")\n    else:\n        raise","preventionTips":["Perform trader-dependent setup in on_start, never in __init__ or on_init","Always attach strategies to a TradingNode/BacktestEngine before exercising their APIs","Check registration state before any call that touches the trader's cache"],"tags":["rust","strategy","lifecycle","trader-registration"],"backgroundTag":"invalid-state-transition","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}