{"record":{"id":"7750f8f373756d46","repo":"nautechsystems/nautilus_trader","slug":"client-already-registered-with-id-client-id","errorCode":null,"errorMessage":"Client already registered with ID {client_id}","messagePattern":"Client already registered with ID (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/execution/src/engine/mod.rs","lineNumber":360,"sourceCode":"    }\n\n    #[must_use]\n    /// Returns any external order claim for the given instrument ID.\n    pub fn get_external_order_claim(&self, instrument_id: &InstrumentId) -> Option<StrategyId> {\n        self.cache.borrow().external_order_claim(instrument_id)\n    }\n\n    /// Registers a new execution client.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if a client with the same ID is already registered.\n    pub fn register_client(&mut self, client: Box<dyn ExecutionClient>) -> anyhow::Result<()> {\n        let client_id = client.client_id();\n        let venue = client.venue();\n\n        if self.clients.contains_key(&client_id) {\n            anyhow::bail!(\"Client already registered with ID {client_id}\");\n        }\n\n        let adapter = ExecutionClientAdapter::new(client);\n\n        if let Some(existing_client_id) = self.routing_map.get(&venue) {\n            anyhow::bail!(\n                \"Venue {venue} already routed to {existing_client_id}, \\\n                 cannot register {client_id} for the same venue\"\n            );\n        }\n\n        self.routing_map.insert(venue, client_id);\n        log::debug!(\"Registered client {client_id}\");\n        self.clients.insert(client_id, adapter);\n        Ok(())\n    }\n\n    /// Registers a default execution client for fallback routing.","sourceCodeStart":342,"sourceCodeEnd":378,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/execution/src/engine/mod.rs#L342-L378","documentation":"ExecutionEngine.register_client refuses to register a second ExecutionClient whose ClientId already exists in self.clients. Client IDs must be unique within the engine; the duplicate is rejected before any routing map is touched.","triggerScenarios":"Calling register_client twice with clients reporting the same client_id() — e.g. constructing two adapters for the same venue/client and registering both at startup.","commonSituations":"Duplicate adapter instantiation in a live-trading config (same client id configured twice); test setups re-registering a fixture client; a retry path that re-registers instead of reusing the existing client.","solutions":["Ensure each client has a unique ClientId before registration","Check contains/lookup before registering, or reuse the existing registered client","Fix the config so the same adapter is not instantiated twice"],"exampleFix":"// before\nengine.register_client(client_a.clone())?;\nengine.register_client(client_a)?; // duplicate ClientId\n// after\nif !engine.clients_registered().contains(&client_a.client_id()) {\n    engine.register_client(client_a)?;\n}","handlingStrategy":"validation","validationCode":"if engine.registered_client_ids().contains(&client.client_id()) {\n    return Err(anyhow!(\"duplicate client {}\", client.client_id()));\n}","typeGuard":null,"tryCatchPattern":"match engine.register_client(client) {\n    Err(e) if e.to_string().contains(\"already registered\") => {/* reuse existing client */},\n    other => other?,\n}","preventionTips":["Generate unique ClientIds per adapter instance in config","Guard startup code against double-registration on retry","Assert uniqueness of client IDs in test fixtures"],"tags":["rust","execution-engine","duplicate-registration","client-id"],"backgroundTag":"resource-already-exists","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"}