{"record":{"id":"8a14f1decf484392","repo":"nautechsystems/nautilus_trader","slug":"failed-to-request-open-orders-for-perm-id-lookup","errorCode":null,"errorMessage":"Failed to request open orders for perm_id lookup: {e}","messagePattern":"Failed to request open orders for perm_id lookup: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/interactive_brokers/src/execution/core.rs","lineNumber":2222,"sourceCode":"        Ok(())\n    }\n\n    async fn resolve_ib_order_id(\n        client: &Arc<Client>,\n        order_selector: IbOrderSelector,\n        account_id: AccountId,\n        request_timeout_secs: u64,\n    ) -> anyhow::Result<i32> {\n        let target_perm_id = match order_selector {\n            IbOrderSelector::OrderId(order_id) => return Ok(order_id),\n            IbOrderSelector::PermId(perm_id) => perm_id,\n        };\n\n        let timeout_dur = Duration::from_secs(request_timeout_secs);\n        let raw_account_id = raw_ib_account_code(&account_id);\n        let subscription = match tokio::time::timeout(timeout_dur, client.all_open_orders()).await {\n            Ok(Ok(subscription)) => subscription,\n            Ok(Err(e)) => anyhow::bail!(\"Failed to request open orders for perm_id lookup: {e}\"),\n            Err(_) => anyhow::bail!(\"Timed out requesting open orders for perm_id lookup\"),\n        };\n        let mut subscription = subscription.filter_data();\n\n        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 {","sourceCodeStart":2204,"sourceCodeEnd":2240,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/interactive_brokers/src/execution/core.rs#L2204-L2240","documentation":"When resolving an IB order_id from a perm_id, the code requests all open orders with a timeout. If client.all_open_orders() returns an Err, this error bails with the underlying cause embedded. It indicates the open-orders request to TWS/Gateway failed at the transport/API level.","triggerScenarios":"Calling the perm_id lookup while the TWS/Gateway connection is broken, the API client is not connected, or IB rejects the reqAllOpenOrders call; the Ok(Err(e)) arm of the timeout-wrapped request.","commonSituations":"Gateway restart during order reconciliation; client disconnected (session drop); attempting lookup before client.connect completes; IB API errors such as invalid client state.","solutions":["Check the embedded cause message for the actual ibapi failure","Ensure the IB client is connected and the session is active before lookup","Reconnect the client and retry the perm_id lookup","Confirm TWS/Gateway API settings allow order requests"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if !client.is_connected() { client.connect(...).await?; }\n// only then attempt the perm_id lookup","typeGuard":null,"tryCatchPattern":"match resolve_perm_id(...).await {\n    Ok(order_id) => order_id,\n    Err(e) if e.to_string().contains(\"Failed to request open orders\") => {\n        reconnect(client).await?;\n        retry_lookup().await?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Check client connection state before order reconciliation","Retry lookup with backoff on transient failures","Ensure TWS API settings permit open-order requests","Re-run reconciliation after any Gateway restart"],"tags":["ibkr","orders","api","reconciliation"],"backgroundTag":"api-request-failed","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"}