{"record":{"id":"81b3f324a5e9c07a","repo":"nautechsystems/nautilus_trader","slug":"account-id-not-found-for-trader","errorCode":null,"errorMessage":"Account ID not found for trader {}","messagePattern":"Account ID not found for trader (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/execution/src/matching_engine/mod.rs","lineNumber":5269,"sourceCode":"                                        &child_order.strategy_id(),\n                                    )\n                                    .unwrap();\n                                log::debug!(\n                                    \"Added position id {position_id} to cache for order {client_order_id}\"\n                                );\n                            }\n\n                            if (!child_order.is_open())\n                                || (matches!(child_order.status(), OrderStatus::PendingUpdate)\n                                    && child_order\n                                        .previous_status()\n                                        .is_some_and(|s| matches!(s, OrderStatus::Submitted)))\n                            {\n                                let account_id = order\n                                    .account_id()\n                                    .or_else(|| self.account_ids.get(&order.trader_id()).copied())\n                                    .ok_or_else(|| {\n                                        anyhow::anyhow!(\n                                            \"Account ID not found for trader {}\",\n                                            order.trader_id()\n                                        )\n                                    })?;\n                                self.process_order(&mut child_order, account_id);\n                            }\n                        }\n                    } else {\n                        log::error!(\n                            \"OTO order {} does not have linked orders\",\n                            order.client_order_id()\n                        );\n                    }\n                }\n                ContingencyType::Oco => {\n                    if let Some(linked_orders_ids) = order.linked_order_ids() {\n                        for client_order_id in linked_orders_ids {\n                            let child_order = match self.order_snapshot(*client_order_id) {","sourceCodeStart":5251,"sourceCodeEnd":5287,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/execution/src/matching_engine/mod.rs#L5251-L5287","documentation":"When the matching engine processes (or child-dispatches) an order it needs an AccountId. It first reads the order's own account_id; failing that it falls back to a trader_id -> account_id map maintained on the engine. If neither yields an account, processing cannot proceed and this error is raised.","triggerScenarios":"Submitting an order whose account_id was never set and whose trader_id is absent from the engine's account_ids map — e.g. orders generated internally (child/contingent/settlement orders) before register_account was called, or a trader_id mismatch between client and matching engine configuration.","commonSituations":"Adding a matching engine/venue without registering all trader accounts; mismatched trader_id naming between the execution client config and the matching engine; child orders derived from a parent order lacking account_id in custom adapters.","solutions":["Register the trader's account on the matching engine (account_ids map) before submitting orders for that trader_id.","Ensure orders are built with account_id set at creation by the execution client.","Verify trader_id spelling/configuration matches exactly between the client and matching engine setup.","If the order is synthesized internally, propagate the parent order's account_id to child orders."],"exampleFix":"// before: engine without the trader's account registered\nlet engine = MatchingEngine::new(venue, omc, clock, ...); // no register_account\nengine.iteration(...)?; // 'Account ID not found for trader T'\n// after: register account for the trader up front\nengine.register_account(trader_id, account_id);\nengine.iteration(...)?;","handlingStrategy":"validation","validationCode":"// before submitting, confirm the order carries an account or the trader is registered\nlet resolvable = order.account_id().is_some()\n    || engine_account_ids.contains_key(&order.trader_id());\nassert!(resolvable, \"no account for trader {}\", order.trader_id());","typeGuard":null,"tryCatchPattern":"match engine.iteration(&mut command_queue) {\n    Err(e) if e.to_string().starts_with(\"Account ID not found for trader\") => {\n        log::error!(\"{e}; registering account and retrying\");\n        engine.register_account(trader_id, account_id);\n        // retry once\n    }\n    other => other,\n}","preventionTips":["Call register_account for every trader before submitting orders to the matching engine.","Set account_id on every order at creation time in the execution client.","Keep trader_id configuration identical between client and matching engine."],"tags":["matching-engine","account-lookup","trader-id","configuration"],"backgroundTag":"resource-not-found","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"}