nautechsystems/nautilus_trader · error

instrument_type or instrument_id required for algo order que

Error message

instrument_type or instrument_id required for algo order query

What it means

The OKX HTTP adapter requires at least one filter to query algo orders: either the OKX `inst_type` (derived from a cached instrument when an `instrument_id` is given) or a `instrument_type` directly. When neither is supplied the request would be invalid per OKX's API, so the client bails before sending it.

Source

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

        end: Option<Timestamp>,
        require_complete_active_coverage: bool,
    ) -> anyhow::Result<AlgoOrderReportSweep> {
        let mut instruments_cache: AHashMap<Ustr, InstrumentAny> = AHashMap::new();
        let mut ambiguous_triggered_child_ids = AHashSet::new();
        let has_specific_lookup = algo_id.is_some() || algo_client_order_id.is_some();
        let start_ns = start.map(UnixNanos::from);
        let end_ns = end.map(UnixNanos::from);
        let mut complete = true;

        let inst_type = if let Some(inst_type) = instrument_type {
            inst_type
        } else if let Some(inst_id) = instrument_id {
            let instrument = self.instrument_from_cache(inst_id.symbol.inner())?;
            let inst_type = okx_instrument_type(&instrument)?;
            instruments_cache.insert(inst_id.symbol.inner(), instrument);
            inst_type
        } else {
            anyhow::bail!("instrument_type or instrument_id required for algo order query")
        };

        let ts_init = self.generate_ts_init();
        let mut reports = Vec::new();
        let mut seen: AHashMap<(String, String), usize> = AHashMap::new();

        if has_specific_lookup {
            let mut params_builder = GetAlgoOrderParamsBuilder::default();

            if let Some(algo_id) = algo_id {
                params_builder.algo_id(algo_id);
            }

            if let Some(client_order_id) = algo_client_order_id {
                params_builder.algo_cl_ord_id(client_order_id.as_str().to_string());
            }

            let params = params_builder

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Pass an `instrument_id` so the adapter can derive the instrument type from cache.
  2. Explicitly pass an `instrument_type` (e.g. SWAP, FUT) to the algo order query.
  3. If querying all algo orders, iterate over the instrument types you care about and issue one query per type.

Example fix

// before
let reports = client.request_algo_order_reports(None, None, ...).await?;
// after
let reports = client.request_algo_order_reports(Some(InstrumentId::from("BTC-USDT-SWAP.OKX")), None, ...).await?;
Defensive patterns

Strategy: validation

Validate before calling

if instrument_type.is_none() && instrument_id.is_none() {
    return Err(anyhow::anyhow!("algo order query needs instrument_type or instrument_id"));
}

Prevention

When it happens

Trigger: Calling the algo-order query/report generation with `instrument_type=None` and `instrument_id=None` (both `Option`s unset).

Common situations: Reconciliation or report generation code that passes only venue/optional filters (e.g. date range) without an instrument type or ID; generic query helpers that build requests from user input where instrument filters were omitted.

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/3285f64bff8f5063. Report an issue: GitHub.