nautechsystems/nautilus_trader · error

unmapped in-scope open order instrument {instrument_id} (tok

Error message

unmapped in-scope open order instrument {instrument_id} (token {order.asset_id}); {hint}

What it means

While building an order status report during reconciliation, the instrument derived from the venue order (via its token asset_id) could not be mapped to a known instrument, and that instrument falls within the collection's load-ids scope. The adapter fails loudly rather than silently skipping an open order it should be able to report on.

Source

Thrown at crates/adapters/polymarket/src/execution/reconciliation.rs:641

        OrderEvidenceScope::Collection { instrument_filter } => match instruments
            .get_cloned(&order.asset_id)
        {
            Some(instrument) => instrument,
            None => {
                let instrument_id =
                    instrument_id_from_market_token(order.market.as_str(), order.asset_id.as_str());

                if instrument_filter.is_some_and(|filter_id| {
                    !polymarket_instrument_ids_equivalent(filter_id, instrument_id)
                }) {
                    return Ok(OrderRowResult {
                        report: None,
                        counted_filtered: false,
                    });
                }

                if instrument_in_load_ids_scope(instrument_id, collection_load_ids) {
                    anyhow::bail!(unmapped_in_scope_message(
                        "open order",
                        instrument_id,
                        Some(&format!("token {}", order.asset_id)),
                        collection_load_ids,
                    ));
                }
                log::debug!("Dropping out-of-scope unmapped open order instrument {instrument_id}");
                return Ok(OrderRowResult {
                    report: None,
                    counted_filtered: true,
                });
            }
        },
    };
    let instrument_id = instrument.id();

    if let OrderEvidenceScope::Collection {
        instrument_filter: Some(filter_id),

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Add the instrument for token {order.asset_id} to the adapter's configured instruments/load ids and reload instruments.
  2. Call the instrument loading path (fetch_instruments / fetch_configured_instruments) covering the market matching the token before reconciling.
  3. Check whether the token belongs to a stale/resolved market and update configuration accordingly.
  4. If the order should genuinely be excluded, ensure it is filtered out before entering build_order_reports_from_orders so it is counted as filtered rather than hitting this bail.

Example fix

// before: reconciling without loading the instrument for the order's token
let reports = exec.build_order_reports_from_orders(&orders)?;
// after: load instruments covering the tokens first
let tokens: Vec<String> = orders.iter().map(|o| o.asset_id.clone()).collect();
exec.ensure_instruments_loaded_for_tokens(&tokens)?;
let reports = exec.build_order_reports_from_orders(&orders)?;
Defensive patterns

Strategy: validation

Validate before calling

// Rust: ensure every open order token maps to a loaded instrument before reconciling
fn all_tokens_mapped(orders: &[OrderRow], instruments: &InstrumentMap) -> bool {
    orders.iter().all(|o| instruments.contains_token(&o.asset_id))
}
assert!(all_tokens_mapped(&orders, &instruments), "load missing instruments before reconcile");

Type guard

fn mapped_instrument<'a>(instruments: &'a InstrumentMap, token: &str) -> Option<&'a Instrument> {
    instruments.by_token(token)
}

Prevention

When it happens

Trigger: build_order_report_from_order (via build_target_order_report / build_order_reports_from_orders) encounters an in-scope open order whose token (order.asset_id) maps to an instrument_id absent from the loaded instrument set, as checked by instrument_in_load_ids_scope.

Common situations: Instrument configuration (load ids) not covering all tokens held by the account; a market was migrated or resolved and token ids changed; new positions opened in markets not listed in the adapter config; loading instruments with a filter that omits some CLOB tokens.

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/2dc12fdf66a2efba. Report an issue: GitHub.