{"record":{"id":"dbb2d96f9d78bc6d","repo":"nautechsystems/nautilus_trader","slug":"venue-venue-already-routed-to-existing-client-i-dbb2d9","errorCode":null,"errorMessage":"Venue {venue} already routed to {existing_client_id}, cannot register {client_id} for the same venue","messagePattern":"Venue (.+?) already routed to (.+?), cannot register (.+?) for the same venue","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/execution/src/engine/mod.rs","lineNumber":366,"sourceCode":"    }\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.\n    pub fn register_default_client(&mut self, client: Box<dyn ExecutionClient>) {\n        let client_id = client.client_id();\n        let adapter = ExecutionClientAdapter::new(client);\n\n        self.clients.insert(client_id, adapter);\n        self.default_client_id = Some(client_id);","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/execution/src/engine/mod.rs#L348-L384","documentation":"The execution engine maintains a routing_map that maps each Venue to exactly one client ID. This error is raised during register_client when the venue is already routed to a different client, because a second client cannot be registered for the same venue — order routing would be ambiguous.","triggerScenarios":"Calling ExecutionEngine::register_client with an ExecutionClient whose venue is already present in the engine's routing_map pointing at another client ID. In tests it is hit when registering a second client for the same venue (e.g. dual hedge legs across clients in reconciliation scenarios).","commonSituations":"Configuring two execution clients (e.g. two accounts or a live+test setup) that both resolve to the same Venue; re-registering a client under a new ID after the old one is still routed; a reconciliation test registering both hedge legs whose clients share a venue.","solutions":["Deregister the existing client with deregister_client first (it also removes its routing_map entries), then register the new client.","Register the second client with a distinct venue so each venue maps to one client.","If the same client should own the venue, check register_client's idempotency: if the existing routed client_id equals the new client_id, no error occurs only via register_venue_routing; otherwise reuse the already-registered client.","Inspect self.routing_map (or call the engine's lookup APIs) before registering to confirm the venue is unclaimed."],"exampleFix":"// before\nengine.register_client(client_b)?; // panics/bails: venue already routed to client_a\n// after\nengine.deregister_client(client_a_id)?;\nengine.register_client(client_b)?;","handlingStrategy":"validation","validationCode":"if engine.routing_target(&venue).is_some() {\n    // venue already claimed: deregister existing client or pick another venue\n}","typeGuard":null,"tryCatchPattern":"match engine.register_client(client) {\n    Err(e) if e.to_string().contains(\"already routed\") => log::warn!(\"venue already claimed, skipping: {e}\"),\n    other => other?,\n}","preventionTips":["Build the venue→client mapping from a single config source and validate for duplicate venues before registering.","Register clients one per venue; use register_venue_routing only after confirming the venue is unclaimed.","When swapping clients for a venue, always deregister the old client first."],"tags":["execution-engine","venue-routing","duplicate-registration","rust"],"backgroundTag":"conflicting-config-options","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"}