nautechsystems/nautilus_trader · error · anyhow::Error

Failed to build algo order params: {e}

Error message

Failed to build algo order params: {e}

What it means

When fetching algo order reports, the adapter assembles OKX request params with a typed builder; a failed build() is wrapped as 'Failed to build algo order params: {e}'. This happens during algo order report sweeps (pending/history) before any HTTP request is made.

Source

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

        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
                .build()
                .map_err(|e| anyhow::anyhow!(format!("Failed to build algo order params: {e}")))?;
            let mut orders = match self.inner.get_algo_order(params).await {
                Ok(orders) => orders,
                Err(e) if e.is_order_not_found() => {
                    return Ok(AlgoOrderReportSweep {
                        reports,
                        complete,
                        ambiguous_triggered_child_ids,
                    });
                }
                Err(e) => return Err(e.into()),
            };

            if let Some(state) = state {
                orders.retain(|order| order.state == state);
            }

            complete &= self
                .collect_algo_reports(

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Read the inner builder error for the exact violated rule
  2. Provide exactly one of algo_id or algo_client_order_id
  3. Validate ID strings are non-empty before building

Example fix

// before
builder.algo_id(algo_id).algo_cl_ord_id(cl_id);
// after
builder.algo_id(algo_id); // only one identifier
Defensive patterns

Strategy: validation

Validate before calling

if algo_id.is_some() && algo_client_order_id.is_some() {
    return Err("Set only one of algo_id or algo_client_order_id".into());
}

Try / catch

match client.algo_order_reports(...).await {
    Err(e) if e.to_string().contains("Failed to build algo order params") => {
        // adjust builder inputs per wrapped cause and retry
    }
    other => other?,
}

Prevention

When it happens

Trigger: Builder validation failure, e.g. both algo_id and algo_client_order_id set when OKX requires exactly one, or missing mandatory fields for the chosen ord_type.

Common situations: Setting both algo_cl_ord_id and algo_id; empty ID strings; API surface change in the builder requiring a new mandatory field.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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