nautechsystems/nautilus_trader · error · anyhow::Error

Unsupported OKX algo order status: {e}

Error message

Unsupported OKX algo order status: {e}

What it means

OKX algo order 'state' values are converted into the library's OrderStatus enum via TryInto; when the exchange sends a state the adapter does not map (new/unsupported enum variant, likely from an OKX API update), the conversion fails and this error wraps the inner parse error. The library fails closed rather than guessing an order status.

Source

Thrown at crates/adapters/okx/src/websocket/parse.rs:1543

    ts_init: UnixNanos,
) -> anyhow::Result<OrderStatusReport> {
    let client_order_id = parse_parent_client_order_id(Some(&msg.algo_cl_ord_id), &msg.cl_ord_id);

    // For algo orders that haven't triggered, ord_id will be empty, use algo_id instead
    let venue_order_id = if msg.ord_id.is_empty() {
        VenueOrderId::new(msg.algo_id.as_str())
    } else {
        VenueOrderId::new(msg.ord_id.as_str())
    };

    let order_side = OrderSide::from(msg.side);

    let algo_fields = parse_algo_order_fields(msg)?;

    let status: OrderStatus = msg
        .state
        .try_into()
        .map_err(|e| anyhow::anyhow!("Unsupported OKX algo order status: {e}"))?;

    let quantity = parse_algo_order_quantity(msg, instrument)?;

    let filled_qty = if msg.state == OKXAlgoOrderStatus::Filled
        && !msg.actual_sz.is_empty()
        && msg.actual_sz != "0"
    {
        parse_quantity(msg.actual_sz.as_str(), instrument.size_precision())?
    } else {
        Quantity::zero(instrument.size_precision())
    };

    // Parse limit price if it exists (not -1)
    let price = if is_market_price(algo_fields.ord_px) {
        None
    } else {
        Some(parse_price(
            algo_fields.ord_px,

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Update the adapter's OKXAlgoOrderStatus enum and its TryFrom/OrderStatus mapping to include the new state reported in the error
  2. Check the OKX API changelog for newly introduced algo order states and upgrade the library version that supports them
  3. Log the raw msg.state value to identify the exact offending string, then add a mapping or skip-and-log for it
  4. As a defensive measure at the call site, catch this error and treat the message as unparseable rather than failing the stream

Example fix

// before
let status: OrderStatus = msg
    .state
    .try_into()
    .map_err(|e| anyhow::anyhow!("Unsupported OKX algo order status: {e}"))?;
// after
let status: OrderStatus = match msg.state.try_into() {
    Ok(s) => s,
    Err(e) => {
        log::warn("Unrecognized algo order state {:?}: {e}; skipping", msg.state);
        return Ok(None);
    }
};
Defensive patterns

Strategy: try-catch

Validate before calling

// Rust, pre-check the state string against known OKX algo states
const KNOWN: &[&str] = &["live", "partially_filled", "filled", "canceled"];
if !KNOWN.contains(&msg.state.as_str()) {
    log::warn("Unknown algo state '{}'; upgrade adapter or skip", msg.state);
    return Ok(None);
}

Type guard

fn is_supported_algo_state(state: &str, known: &[OKXAlgoOrderStatus]) -> bool {
    // true when the raw state string maps to a supported variant
    OKXAlgoOrderStatus::try_from_str(state).map(|s| known.contains(&s)).unwrap_or(false)
}

Try / catch

match parse_algo_order_status_report(&msg, &inst, account_id, ts_init) {
    Ok(report) => Some(report),
    Err(e) if e.to_string().contains("Unsupported OKX algo order status") => {
        log::warn("{e}; check OKX API changelog and update adapter enum mapping");
        return Ok(None);
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: An algo order message (WebSocket 'algo-orders' or HTTP algo order fetch) carries a msg.state string that has no OKXAlgoOrderStatus variant mapping to OrderStatus — e.g. a state newly added by OKX or one the adapter deliberately does not support, while parsing fields in parse_algo_order_status_report.

Common situations: OKX adding a new algo state (e.g. a new cancel/trigger state) after the adapter's enum was written; state strings localized or otherwise unexpected in the payload; stale adapter version vs current OKX API enum; handler skipping unsupported algo order types upstream but a raw state still reaching conversion.

Related errors


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