{"record":{"id":"c386136fce454f7e","repo":"nautechsystems/nautilus_trader","slug":"venue-venue-already-routed-to-existing-client-i-c38613","errorCode":null,"errorMessage":"Venue {venue} already routed to {existing_client_id}, cannot re-route to {client_id}","messagePattern":"Venue (.+?) already routed to (.+?), cannot re-route to (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/execution/src/engine/mod.rs","lineNumber":556,"sourceCode":"\n    /// Sets routing for a specific venue to a given client ID.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the client ID is not registered.\n    pub fn register_venue_routing(\n        &mut self,\n        client_id: ClientId,\n        venue: Venue,\n    ) -> anyhow::Result<()> {\n        if !self.clients.contains_key(&client_id) {\n            anyhow::bail!(\"No client registered with ID {client_id}\");\n        }\n\n        if let Some(existing_client_id) = self.routing_map.get(&venue)\n            && *existing_client_id != client_id\n        {\n            anyhow::bail!(\n                \"Venue {venue} already routed to {existing_client_id}, \\\n                 cannot re-route to {client_id}\"\n            );\n        }\n\n        self.routing_map.insert(venue, client_id);\n        log::info!(\"Set client {client_id} routing for {venue}\");\n        Ok(())\n    }\n\n    /// Registers the OMS (Order Management System) type for a strategy.\n    ///\n    /// If an OMS type is already registered for this strategy, it will be overridden.\n    pub fn register_oms_type(&mut self, strategy_id: StrategyId, oms_type: OmsType) {\n        self.oms_overrides.insert(strategy_id, oms_type);\n        log::info!(\"Registered OMS::{oms_type:?} for {strategy_id}\");\n    }\n","sourceCodeStart":538,"sourceCodeEnd":574,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/execution/src/engine/mod.rs#L538-L574","documentation":"Each venue can be routed to only one client. register_venue_routing bails when the venue already maps to a different client ID; re-routing to a new client is not permitted, while routing the same venue to the same client is a no-op (allowed).","triggerScenarios":"Calling ExecutionEngine::register_venue_routing for a venue that is already present in routing_map with a different client_id than the one passed in.","commonSituations":"Assigning a venue to a second client after register_client already claimed it (e.g. switching accounts at runtime); config lists two routes for the same venue; a test registers both a primary and hedge client for one venue.","solutions":["If re-routing is intended, deregister the currently routed client (deregister_client removes its routing entries) and then register the new route.","Choose a distinct venue per client so each venue maps to one route.","Skip the call when the existing route already equals the target client (it is a legal no-op).","Validate routing configuration at startup for duplicate venue entries before applying them."],"exampleFix":"// before\nengine.register_venue_routing(client_b_id.clone(), venue)?; // venue routed to client_a\n// after\nif engine.routing_target(&venue) != Some(&client_b_id) {\n    engine.deregister_client(current_routed_id)?;\n}\nengine.register_venue_routing(client_b_id.clone(), venue)?;","handlingStrategy":"validation","validationCode":"// skip when the route already points at the target client\nif engine.routing_target(&venue).as_ref() != Some(&client_id) {\n    engine.register_venue_routing(client_id, venue)?;\n}","typeGuard":null,"tryCatchPattern":"match engine.register_venue_routing(client_id.clone(), venue.clone()) {\n    Err(e) if e.to_string().contains(\"cannot re-route\") => log::warn!(\"venue {venue} stays on its existing client\"),\n    other => other?,\n}","preventionTips":["Validate routing config for duplicate venue entries at startup.","Treat same-client re-routing as a no-op and skip the call.","Deregister the currently routed client before switching a venue to a new client."],"tags":["execution-engine","venue-routing","conflict","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-14T05:17:10.506Z"}