{"record":{"id":"60c367e53773cd15","repo":"nautechsystems/nautilus_trader","slug":"actor-has-no-trader-id","errorCode":null,"errorMessage":"Actor {} has no trader ID","messagePattern":"Actor (.+?) has no trader ID","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/common/src/actor/data_actor.rs","lineNumber":5763,"sourceCode":"    ///\n    /// Returns an error if the actor is not registered, the endpoint label is invalid, the live\n    /// runner is unavailable, or the command channel is closed.\n    #[cfg(feature = \"live\")]\n    pub fn reconnect_socket(&self, client_id: ClientId, endpoint: &str) -> anyhow::Result<()> {\n        let endpoint = socket_endpoint(endpoint)?;\n\n        if !self.is_properly_registered() {\n            anyhow::bail!(\n                \"Actor {} has not been registered with a Trader\",\n                self.actor_id\n            );\n        }\n\n        let sender = try_get_system_command_sender()\n            .ok_or_else(|| anyhow::anyhow!(\"Live runner system command channel is unavailable\"))?;\n        let trader_id = self\n            .trader_id\n            .ok_or_else(|| anyhow::anyhow!(\"Actor {} has no trader ID\", self.actor_id))?;\n        let command = ReconnectSocket::new(trader_id, client_id, endpoint, self.timestamp_ns());\n        sender\n            .send(SystemCommand::ReconnectSocket(command))\n            .map_err(|_| anyhow::anyhow!(\"Live runner system command channel is closed\"))?;\n        Ok(())\n    }\n\n    #[cfg(test)]\n    pub fn quote_handler_count(&self) -> usize {\n        self.quote_handlers.len()\n    }\n\n    #[cfg(test)]\n    pub fn trade_handler_count(&self) -> usize {\n        self.trade_handlers.len()\n    }\n\n    #[cfg(test)]","sourceCodeStart":5745,"sourceCodeEnd":5781,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/actor/data_actor.rs#L5745-L5781","documentation":"DataActor::reconnect_socket needs the actor's TraderId to build a ReconnectSocket command. `self.trader_id` is an Option that is only populated once the actor is registered with a Trader; if it is None the command cannot be addressed and the method returns this anyhow error.","triggerScenarios":"Calling reconnect_socket on a DataActor whose trader_id is None — i.e. the actor was never registered with a Trader (no register_with_trader / Trader registration) before the reconnect request was made.","commonSituations":"Instantiating a DataActor and calling socket-reconnect logic directly without adding it to a Trader; wiring actors manually instead of through the node builder; lifecycle races where reconnect is requested during actor startup before registration completes.","solutions":["Register the actor with a Trader before calling reconnect_socket (trader.register_actor / trader.add_actor) so trader_id is set.","Verify registration succeeded — the method already logs a warning when the actor is not registered; fix the registration path that produced it.","Defer reconnect_socket calls until after the actor's on_start lifecycle, when registration is guaranteed.","In tests, set the actor's trader_id explicitly (or register with a test Trader) before exercising reconnect logic."],"exampleFix":"// before\nlet actor = MyDataActor::new(config);\nactor.reconnect_socket(client_id, endpoint)?; // trader_id is None\n\n// after\nlet actor = MyDataActor::new(config);\ntrader.add_actor(actor.clone()); // populates trader_id\nactor.reconnect_socket(client_id, endpoint)?;","handlingStrategy":"validation","validationCode":"// Rust\nif actor.trader_id.is_none() {\n    anyhow::bail!(\"actor {} must be registered with a Trader before reconnect_socket\", actor.actor_id);\n}","typeGuard":"fn has_trader_id(actor: &DataActor) -> bool { actor.trader_id.is_some() }","tryCatchPattern":"if let Err(e) = actor.reconnect_socket(client_id, endpoint) {\n    if e.to_string().contains(\"has no trader ID\") {\n        tracing::error!(\"actor not registered with a Trader: {e}\");\n    } else {\n        return Err(e);\n    }\n}","preventionTips":["Always register actors with a Trader before starting them.","Trigger reconnect logic from on_start or later lifecycle hooks, never in the constructor.","Use the node builder API rather than wiring actors manually to guarantee registration order."],"tags":["actor","trader-id","lifecycle","not-registered"],"backgroundTag":"missing-required-argument","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"}