nautechsystems/nautilus_trader · error

registered order instrument {} does not match requested inst

Error message

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

What it means

When a registered order context exists for the target venue order, its identity.instrument_id must match the requested instrument_id. This ensure! fires when the context registered in order_contexts belongs to a different market than requested. Like the cached-order instrument check, it guards against cross-market report generation.

Source

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

                            .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!(
                    context.identity.client_order_id == cached_order.client_order_id()
                        && context.identity.instrument_id == cached_order.instrument_id()
                        && context.identity.order_side == cached_order.order_side()
                        && context.identity.order_type == cached_order.order_type()
                        && context.time_in_force == cached_order.time_in_force(),
                    "registered order context for {venue_order_id} contradicts cached order {}",
                    cached_order.client_order_id(),
                );
            }
        }

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Pass the instrument id from the registered context (context.identity.instrument_id)
  2. Omit requested_instrument_id so the check is skipped
  3. Fix instrument id construction to use the same source used at order submission

Example fix

// before
let report = client.generate_order_status_report(None, void_id, Some(default_instrument)).await?;
// after
let instrument_id = order_contexts.get(&void_id).map(|c| c.identity.instrument_id);
let report = client.generate_order_status_report(None, void_id, instrument_id).await?;
Defensive patterns

Strategy: validation

Validate before calling

if let Some(ctx) = order_contexts.get(&venue_order_id) {
    anyhow::ensure!(ctx.identity.instrument_id == instrument_id, "registered context instrument mismatch");
}

Type guard

fn context_instrument(ctxs: &OrderContexts, void_id: &VenueOrderId, iid: &InstrumentId) -> bool {
    ctxs.get(void_id).map(|c| c.identity.instrument_id == *iid).unwrap_or(false)
}

Try / catch

match client.generate_fill_reports_impl(None, void_id, Some(iid)).await {
    Err(e) if e.to_string().contains("registered order instrument") => retry_with_registered_instrument(),
    other => other?,
}

Prevention

When it happens

Trigger: generate_order_status_report_impl or generate_fill_reports_impl with requested_instrument_id that differs from the instrument stored in the order context registered under venue_order_id.

Common situations: Passing a default/hardcoded instrument id for all queries in a multi-instrument strategy; instrument id changed between submit and query (wrong token id / condition id).

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/3584147eba8009a3. Report an issue: GitHub.