nautechsystems/nautilus_trader · error · anyhow::Error

Failed to request open orders for perm_id lookup: {e}

Error message

Failed to request open orders for perm_id lookup: {e}

What it means

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.

Source

Thrown at crates/adapters/interactive_brokers/src/execution/core.rs:2222

        Ok(())
    }

    async fn resolve_ib_order_id(
        client: &Arc<Client>,
        order_selector: IbOrderSelector,
        account_id: AccountId,
        request_timeout_secs: u64,
    ) -> anyhow::Result<i32> {
        let target_perm_id = match order_selector {
            IbOrderSelector::OrderId(order_id) => return Ok(order_id),
            IbOrderSelector::PermId(perm_id) => perm_id,
        };

        let timeout_dur = Duration::from_secs(request_timeout_secs);
        let raw_account_id = raw_ib_account_code(&account_id);
        let subscription = match tokio::time::timeout(timeout_dur, client.all_open_orders()).await {
            Ok(Ok(subscription)) => subscription,
            Ok(Err(e)) => anyhow::bail!("Failed to request open orders for perm_id lookup: {e}"),
            Err(_) => anyhow::bail!("Timed out requesting open orders for perm_id lookup"),
        };
        let mut subscription = subscription.filter_data();

        while let Some(order_result) = subscription.next().await {
            let Orders::OrderData(data) = order_result? else {
                continue;
            };

            if !Self::is_active_open_order(&data.order) {
                continue;
            }

            if !data.order.account.is_empty() && data.order.account != raw_account_id {
                continue;
            }

            if data.order.perm_id != target_perm_id {

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Check the embedded cause message for the actual ibapi failure
  2. Ensure the IB client is connected and the session is active before lookup
  3. Reconnect the client and retry the perm_id lookup
  4. Confirm TWS/Gateway API settings allow order requests
Defensive patterns

Strategy: try-catch

Validate before calling

if !client.is_connected() { client.connect(...).await?; }
// only then attempt the perm_id lookup

Try / catch

match resolve_perm_id(...).await {
    Ok(order_id) => order_id,
    Err(e) if e.to_string().contains("Failed to request open orders") => {
        reconnect(client).await?;
        retry_lookup().await?
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: 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.

Common situations: Gateway restart during order reconciliation; client disconnected (session drop); attempting lookup before client.connect completes; IB API errors such as invalid client state.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/8a14f1decf484392. Report an issue: GitHub.