nautechsystems/nautilus_trader · error

cached order instrument {} does not match requested instrume

Error message

cached order instrument {} does not match requested instrument {requested_instrument_id}

What it means

If an instrument_id was requested, resolve_target_order_authority checks the cached order's instrument matches it. This ensure! fires when the cached order belongs to a different market/instrument than the one requested. It prevents generating an order status or fill report against the wrong market.

Source

Thrown at crates/adapters/polymarket/src/execution/reports.rs:158

                anyhow::ensure!(
                    cached_venue_order_id == venue_order_id,
                    "cached client order {} is associated with venue order {cached_venue_order_id}, not requested venue order {venue_order_id}",
                    cached_order.client_order_id(),
                );
            } else {
                anyhow::ensure!(
                    cached_client_order_id == client_order_id
                        || self
                            .order_contexts
                            .venue_order_id(&cached_order.client_order_id())
                            == Some(venue_order_id),
                    "cached client order {} has no association with requested venue order {venue_order_id}",
                    cached_order.client_order_id(),
                );
            }

            if let Some(requested_instrument_id) = requested_instrument_id {
                anyhow::ensure!(
                    cached_order.instrument_id() == requested_instrument_id,
                    "cached order instrument {} does not match requested instrument {requested_instrument_id}",
                    cached_order.instrument_id(),
                );
            }
        }

        if let Some(context) = context {
            if let Some(requested_instrument_id) = requested_instrument_id {
                anyhow::ensure!(
                    context.identity.instrument_id == requested_instrument_id,
                    "registered order instrument {} does not match requested instrument {requested_instrument_id}",
                    context.identity.instrument_id,
                );
            }

            if let Some(cached_order) = cached_order.as_ref() {
                anyhow::ensure!(

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Omit requested_instrument_id or pass cached_order.instrument_id()
  2. Correct the instrument id in the calling code to the order's actual market
  3. Normalize instrument id construction so it matches submission-time formatting

Example fix

// before
let report = client.generate_order_status_report(Some(coid), void_id, Some(wrong_instrument)).await?;
// after
let instrument_id = core.cache().order_owned(&coid).map(|o| *o.instrument_id());
let report = client.generate_order_status_report(Some(coid), void_id, instrument_id).await?;
Defensive patterns

Strategy: validation

Validate before calling

let expected = core.cache().order_owned(&coid).map(|o| *o.instrument_id());
anyhow::ensure!(requested == expected, "instrument mismatch for order");

Type guard

fn instrument_matches(core: &Cache, coid: &ClientOrderId, iid: &InstrumentId) -> bool {
    core.order_owned(coid).map(|o| o.instrument_id() == iid).unwrap_or(false)
}

Try / catch

match client.generate_order_status_report(Some(coid), void_id, Some(iid)).await {
    Err(e) if e.to_string().contains("does not match requested instrument") => retry_without_instrument(),
    other => other?,
}

Prevention

When it happens

Trigger: Calling query_order_command, generate_order_status_report_impl, or generate_fill_reports_impl with requested_instrument_id set to a market different from the cached order's instrument_id.

Common situations: Multi-market strategies passing the wrong instrument id alongside an order id; instrument id formatted differently (case/precision) than at order submission; copy-paste across instruments.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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