nautechsystems/nautilus_trader · error

Failed to query order {}: {}

Error message

Failed to query order {}: {}

What it means

BybitHttpClient's order-query path first resolves the instrument from its local cache; if that lookup fails (the cache-miss error is logged at error level), the wrapper converts it into 'Failed to query order {}: {}' where the first {} is the client_order_id or venue_order_id (or 'unknown' if neither was provided) and the second is the underlying cause. The query cannot proceed without instrument metadata to build the Bybit symbol/category parameters.

Source

Thrown at crates/adapters/bybit/src/http/client.rs:3169

        let order = &response.result.list[0];
        let ts_init = self.generate_ts_init();

        log::debug!(
            "Query order response: symbol={}, order_id={}, order_link_id={}",
            order.symbol.as_str(),
            order.order_id.as_str(),
            order.order_link_id.as_str()
        );

        let instrument = self
            .instrument_from_cache(&instrument_id.symbol)
            .map_err(|e| {
                log::error!(
                    "Instrument cache miss for symbol '{}': {}",
                    instrument_id.symbol.as_str(),
                    e
                );
                anyhow::anyhow!(
                    "Failed to query order {}: {}",
                    client_order_id
                        .as_ref()
                        .map(|id| id.to_string())
                        .or_else(|| venue_order_id.as_ref().map(|id| id.to_string()))
                        .unwrap_or_else(|| "unknown".to_string()),
                    e
                )
            })?;

        log::debug!("Retrieved instrument from cache: id={}", instrument.id());

        let report =
            parse_order_status_report(order, &instrument, account_id, ts_init).map_err(|e| {
                log::error!(
                    "Failed to parse order status report for {}: {}",
                    order.order_link_id.as_str(),
                    e

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Load instruments for the relevant product type before querying orders so the symbol resolves from cache
  2. Always pass client_order_id or venue_order_id when querying order status
  3. Include the traded symbol in the instrument provider filter config
  4. Restart/reload instruments if the order's instrument was listed after client initialization

Example fix

// before
let status = client.query_order(None, None, instrument_id).await?; // no ids, maybe no instrument
// after
client.load_instruments_all(product_types).await?;
let status = client.query_order(Some(client_order_id), Some(venue_order_id), instrument_id).await?;
Defensive patterns

Strategy: validation

Validate before calling

if client.get_instrument(&instrument_id.symbol.inner()).is_none() {
    client.load_instruments_all(product_types).await?;
}
assert!(client_order_id.is_some() || venue_order_id.is_some(), "need an order id");

Try / catch

match client.query_order(client_order_id, venue_order_id, instrument_id).await {
    Ok(status) => status,
    Err(e) if e.to_string().contains("Failed to query order") => {
        client.load_instruments_all(product_types).await?;
        client.query_order(client_order_id, venue_order_id, instrument_id).await?
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling query_order/order_status for an order whose instrument_id symbol is not in the instruments cache (instruments never loaded or filtered out), or calling with neither client_order_id nor venue_order_id so the identifier is 'unknown'.

Common situations: Reconciliation or order-status polling after a node restart with an instrument provider that excludes the traded symbol; querying orders for instruments added after startup; passing None for both order identifiers.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


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