nautechsystems/nautilus_trader · error

No index price returned from OKX

Error message

No index price returned from OKX

What it means

request_index_price expects OKX's get_index_tickers to return at least one entry; an empty response array means the exchange returned no index price for the requested instId, so this ok_or_else error is raised instead of panicking on first().

Source

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

    ) -> anyhow::Result<IndexPriceUpdate> {
        // Index tickers endpoint requires base pair format (e.g., BTC-USDT)
        let symbol = instrument_id.symbol.inner();
        let (base, quote) = parse_base_quote_from_symbol(symbol.as_str())?;
        let inst_id = format!("{base}-{quote}");

        let mut params = GetIndexTickerParamsBuilder::default();
        params.inst_id(Ustr::from(&inst_id));
        let params = params.build().map_err(|e| anyhow::anyhow!(e))?;

        let resp = self
            .inner
            .get_index_tickers(params)
            .await
            .map_err(|e| anyhow::anyhow!(e))?;

        let raw = resp
            .first()
            .ok_or_else(|| anyhow::anyhow!("No index price returned from OKX"))?;
        let inst = self.instrument_from_cache(instrument_id.symbol.inner())?;
        let ts_init = self.generate_ts_init();

        let index_price =
            parse_index_price_update(raw, instrument_id, inst.price_precision(), ts_init)
                .map_err(|e| anyhow::anyhow!(e))?;
        Ok(index_price)
    }

    /// Requests an order book snapshot for the `instrument_id`.
    ///
    /// # Errors
    ///
    /// Returns an error if the HTTP request fails or book parsing fails.
    pub async fn request_book_snapshot(
        &self,
        instrument_id: InstrumentId,
        depth: Option<u32>,

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Verify the instrument id maps to a valid OKX index ticker (call /api/v5/market/index-tickers manually).
  2. Check that parse_base_quote_from_symbol produced the correct inst_id for your symbol.
  3. Confirm the instrument is not delisted/suspended on OKX.
  4. Handle the empty case upstream by skipping the update instead of treating it as fatal.

Example fix

// before
let raw = resp.first().ok_or_else(|| anyhow::anyhow!("No index price returned from OKX"))?;
// after
let Some(raw) = resp.first() else {
    tracing::warn!("OKX returned no index ticker for {inst_id}; skipping update");
    return Ok(None);
};
Defensive patterns

Strategy: fallback

Validate before calling

let exists = okx_index_instruments.contains(inst_id.as_str());
if !exists { return Ok(None); }

Try / catch

let Some(raw) = resp.first() else {
    tracing::warn!("no index ticker for {inst_id}");
    return Ok(None); // or retry
};

Prevention

When it happens

Trigger: Requesting an index price for an instId that OKX does not recognize or that currently has no ticker data (e.g. a delisted index or a wrongly derived base-quote pair).

Common situations: Subscribing to an index price for a symbol whose base/quote were misparsed, using a recently delisted instrument, or OKX returning an empty data array for a temporarily suspended index.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


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