{"record":{"id":"b4f994f356766653","repo":"nautechsystems/nautilus_trader","slug":"execution-client-should-be-initialized","errorCode":null,"errorMessage":"Execution client should be initialized","messagePattern":"Execution client should be initialized","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/backtest/src/exchange.rs","lineNumber":1872,"sourceCode":"                return;\n            }\n            TradingCommand::ModifyOrders(mut command) => {\n                command\n                    .modifies\n                    .retain(|modify| !self.process_modify_submitted_order(modify));\n\n                if command.modifies.is_empty() {\n                    return;\n                }\n                TradingCommand::ModifyOrders(command)\n            }\n            command => command,\n        };\n\n        let account_id = if let Some(exec_client) = &self.exec_client {\n            exec_client.account_id()\n        } else {\n            panic!(\"Execution client should be initialized\");\n        };\n\n        if let TradingCommand::SubmitOrderList(ref command) = command {\n            let mut orders: Vec<OrderAny> = self\n                .cache\n                .borrow()\n                .orders_for_ids(&command.order_list.client_order_ids, command);\n\n            for order in &mut orders {\n                let order_instrument_id = order.instrument_id();\n                if let Some(matching_engine) = self.matching_engines.get_mut(&order_instrument_id) {\n                    matching_engine.process_order(order, account_id);\n                } else {\n                    panic!(\"Matching engine not found for instrument {order_instrument_id}\");\n                }\n            }\n\n            return;","sourceCodeStart":1854,"sourceCodeEnd":1890,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/backtest/src/exchange.rs#L1854-L1890","documentation":"The backtest exchange panicked because a trading command required a portfolio execution client, but `self.exec_client` was `None`. In NautilusTrader's backtest engine the SimulatedExchange needs an initialized execution client to resolve the account that will process order submissions. This is an internal invariant of the backtest engine: `execute` was called before the client was wired up.","triggerScenarios":"Calling `SimulatedExchange.execute(...)` with a `SubmitOrderList` (or other `TradingCommand`) when no execution client was registered via `set_exec_client(...)` / the builder was not fully configured.","commonSituations":"Programmatically constructing a `BacktestEngine` or `SimulatedExchange` and forgetting to add the execution client/venue configuration; constructing an exchange by hand in tests without calling the exec-client setter; version changes in the backtest builder API where the setup call was renamed or dropped.","solutions":["Add the execution client to the backtest before executing commands (e.g. add a `SimulatedExchangeConfig`/venue with execution enabled or call the engine's exec-client registration API).","Ensure `BacktestEngine.add_venue(...)` (or equivalent setup) runs before any `execute`/command submission.","Check the order of initialization so `exec_client` is set before the data loop starts processing commands."],"exampleFix":"// before\nlet mut engine = BacktestEngine::new();\nengine.add_data(...);\nengine.run(); // panic: no exec client\n// after\nlet mut engine = BacktestEngine::new();\nengine.add_venue(SimulatedExchangeConfig::default());\nengine.add_data(...);\nengine.run();","handlingStrategy":"validation","validationCode":"// before running the backtest\nassert!(engine.exec_client_account_id().is_some(), \"Add a venue/exec client config before executing commands\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always configure venues via `add_venue` before `run()`","Keep backtest setup in one ordered function: venues -> data -> strategies -> run","Cover engine construction in an integration smoke test that submits an order"],"tags":["backtest","panic","initialization","rust"],"backgroundTag":"internal-invariant-violation","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"}