{"record":{"id":"68916ccdc43a4aff","repo":"nautechsystems/nautilus_trader","slug":"cannot-resolve-perm-target-perm-id-matching-ope","errorCode":null,"errorMessage":"Cannot resolve PERM-{target_perm_id}: matching open order has no IB order_id","messagePattern":"Cannot resolve PERM-(.+?): matching open order has no IB order_id","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/interactive_brokers/src/execution/core.rs","lineNumber":2245,"sourceCode":"        while let Some(order_result) = subscription.next().await {\n            let Orders::OrderData(data) = order_result? else {\n                continue;\n            };\n\n            if !Self::is_active_open_order(&data.order) {\n                continue;\n            }\n\n            if !data.order.account.is_empty() && data.order.account != raw_account_id {\n                continue;\n            }\n\n            if data.order.perm_id != target_perm_id {\n                continue;\n            }\n\n            if data.order_id == 0 {\n                anyhow::bail!(\n                    \"Cannot resolve PERM-{target_perm_id}: matching open order has no IB order_id\"\n                );\n            }\n\n            return Ok(data.order_id);\n        }\n\n        anyhow::bail!(\"Cannot resolve PERM-{target_perm_id}: no matching open order found\")\n    }\n\n    fn is_active_open_order(order: &ibapi::orders::Order) -> bool {\n        !order.deactivate\n    }\n\n    fn is_definitive_order_submit_error(error: &ibapi::Error) -> bool {\n        matches!(\n            error,\n            ibapi::Error::InvalidArgument(_) | ibapi::Error::ServerVersion(_, _, _)","sourceCodeStart":2227,"sourceCodeEnd":2263,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/interactive_brokers/src/execution/core.rs#L2227-L2263","documentation":"During perm_id lookup, a matching open order was found whose IB order_id is 0 (unassigned). IB uses order_id 0 for orders not originating from this API client (e.g. placed manually in TWS), so the perm_id cannot be mapped back to an API order_id and this error bails.","triggerScenarios":"An order placed outside this API session (manual in TWS, or from a different client) has a perm_id equal to the target, but data.order_id == 0 in the open-orders snapshot.","commonSituations":"Reconciling orders placed manually or by another automation session; adapter restarted with a new client_id so IB returns unassigned order_ids; resolving a perm_id that belongs to a non-API order.","solutions":["Place orders through the same API client that is performing the lookup","Re-request open orders after IB assigns an order_id, or use reqOpenOrders for the owning client to trigger assignment","Match orders by perm_id directly instead of requiring an API order_id","Verify you are resolving the correct perm_id (not one belonging to a manual order)"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// after finding data.order.perm_id == target_perm_id, check availability first\nif data.order_id == 0 { /* cannot map via API order_id; use perm_id-based handling */ }","typeGuard":"fn has_api_order_id(data: &OrderData) -> Option<i32> {\n    (data.order_id != 0).then_some(data.order_id)\n}","tryCatchPattern":"match resolve_perm_id(perm_id).await {\n    Ok(order_id) => order_id,\n    Err(e) if e.to_string().contains(\"has no IB order_id\") => {\n        info!(\"PERM-{perm_id} is a non-API order; matching by perm_id only\");\n        fall_back_to_perm_id_matching(perm_id)\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Place and manage orders through the same API client performing reconciliation","Use a stable client_id so IB retains order_id assignments","Treat perm_id as the canonical external identifier, not order_id","Skip or flag manual orders instead of failing the whole reconciliation"],"tags":["ibkr","orders","reconciliation","perm-id"],"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-14T05:17:10.506Z"}