nautechsystems/nautilus_trader · error · anyhow::Error

Instrument ID required if `instrument_type` not provided

Error message

Instrument ID required if `instrument_type` not provided

What it means

Order history requests to OKX require either an explicit instrument_type (inst_type) or an Instrument ID from which the adapter derives the instrument type via the cache. If neither is given, params cannot be built and anyhow::anyhow! is returned.

Source

Thrown at crates/adapters/okx/src/http/client.rs:4195

        {
            return self
                .request_spread_order_status_reports_scoped(
                    account_id,
                    instrument_id,
                    start,
                    end,
                    open_only,
                    limit,
                    scope,
                )
                .await;
        }

        let instrument_type = if let Some(instrument_type) = instrument_type {
            instrument_type
        } else {
            let instrument_id = instrument_id.ok_or_else(|| {
                anyhow::anyhow!("Instrument ID required if `instrument_type` not provided")
            })?;
            let instrument = self.instrument_from_cache(instrument_id.symbol.inner())?;
            okx_instrument_type(&instrument)?
        };

        let mut history_base = GetOrderHistoryParamsBuilder::default();
        history_base.inst_type(instrument_type);

        if let Some(instrument_id) = instrument_id.as_ref() {
            history_base.inst_id(instrument_id.symbol.inner().to_string());
        }
        let history_base = history_base.build().map_err(|e| anyhow::anyhow!(e))?;

        let mut pending_base = GetOrderListParamsBuilder::default();
        pending_base.inst_type(instrument_type);

        if let Some(instrument_id) = instrument_id.as_ref() {
            pending_base.inst_id(instrument_id.symbol.inner().to_string());

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Provide instrument_id so the type is derived from the cached instrument
  2. Provide instrument_type explicitly (e.g. SPOT, SWAP, FUTURES, OPTION)
  3. Ensure the instrument cache is loaded before calling if relying on inference

Example fix

// before
client.get_order_history(None, None, start, end, ...).await?;
// after
client.get_order_history(None, Some(instrument_id), start, end, ...).await?;
Defensive patterns

Strategy: validation

Validate before calling

if instrument_type.is_none() && instrument_id.is_none() {
    return Err("Provide either instrument_type or instrument_id for order history".into());
}

Try / catch

match client.get_order_history(instrument_type, instrument_id, ...).await {
    Err(e) if e.to_string().contains("Instrument ID required") => {
        // retry with an explicit instrument_type
    }
    other => other?,
}

Prevention

When it happens

Trigger: Calling the order-history/report function with instrument_type=None and instrument_id=None; e.g. sweeping all order history without specifying instrument type.

Common situations: Bulk reconciliation scripts that omit both filters; callers assuming the adapter can infer instrument type without an instrument; stale cache making callers skip passing instrument_id.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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