{"record":{"id":"43a6bd735fa9302e","repo":"nautechsystems/nautilus_trader","slug":"trader-cannot-register-with-itself","errorCode":null,"errorMessage":"Trader cannot register with itself","messagePattern":"Trader cannot register with itself","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/system/src/trader.rs","lineNumber":1792,"sourceCode":"    }\n\n    fn state(&self) -> ComponentState {\n        self.state\n    }\n\n    fn transition_state(&mut self, trigger: ComponentTrigger) -> anyhow::Result<()> {\n        self.state = self.state.transition(&trigger)?;\n        log::info!(\"{}\", self.state.variant_name());\n        Ok(())\n    }\n\n    fn register(\n        &mut self,\n        _trader_id: TraderId,\n        _clock: Rc<RefCell<dyn Clock>>,\n        _cache: Rc<RefCell<Cache>>,\n    ) -> anyhow::Result<()> {\n        anyhow::bail!(\"Trader cannot register with itself\")\n    }\n\n    fn on_start(&mut self) -> anyhow::Result<()> {\n        Self::on_start(self)\n    }\n\n    fn on_stop(&mut self) -> anyhow::Result<()> {\n        Self::on_stop(self)\n    }\n\n    fn on_reset(&mut self) -> anyhow::Result<()> {\n        Self::on_reset(self)\n    }\n\n    fn on_dispose(&mut self) -> anyhow::Result<()> {\n        Self::on_dispose(self)\n    }\n}","sourceCodeStart":1774,"sourceCodeEnd":1810,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/system/src/trader.rs#L1774-L1810","documentation":"Trader's Component register trait method is intentionally unimplemented for Trader itself — a trader cannot be registered as a component within itself. The registration call is rejected unconditionally with this bail.","triggerScenarios":"Calling register(trader_id, clock, cache) on a Trader instance, e.g. generic code that registers all components including the trader, or passing the trader as a strategy/actor to another trader.","commonSituations":"Generic component-registration loops that don't exclude the trader; mistakenly adding a Trader to another Trader's component list; refactored initialization code that treats Trader like any Actor.","solutions":["Exclude the Trader itself from generic component registration loops","Register only strategies, actors, and exec algorithms with the trader, not trader instances","If generic code calls register, filter by type: skip components that are Traders"],"exampleFix":"// before\nfor component in components {\n    component.register(trader_id, clock.clone(), cache.clone())?;\n}\n// after\nfor component in components {\n    if component.id() != self.trader_id().into() {\n        component.register(trader_id, clock.clone(), cache.clone())?;\n    }\n}","handlingStrategy":"type-guard","validationCode":"assert!(component.id() != trader.id());","typeGuard":"fn is_trader(c: &dyn Component) -> bool { c.as_any().is::<Trader>() }","tryCatchPattern":null,"preventionTips":["Filter the Trader out of generic component registration loops","Never pass a Trader where an Actor/Strategy is expected"],"tags":["rust","trader","lifecycle"],"backgroundTag":"unsupported-operation","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"}