nautechsystems/nautilus_trader · error · anyhow::Error

unrecognized settlement currency '{settle_coin}'

Error message

unrecognized settlement currency '{settle_coin}'

What it means

resolve_settlement_currency maps a Bybit settleCoin to either the base or quote currency of the pair. Linear contracts settle in the quote currency and inverse contracts in the base; if settleCoin matches neither, the adapter cannot determine the settlement currency and throws this error while parsing the instrument definition.

Source

Thrown at crates/adapters/bybit/src/common/parse.rs:1345

        .parse()
        .with_context(|| format!("Failed to parse {field}='{value}' as u64 millis"))?;
    let nanos = millis
        .checked_mul(NANOSECONDS_IN_MILLISECOND)
        .context("millisecond timestamp overflowed when converting to nanoseconds")?;
    Ok(UnixNanos::from(nanos))
}

fn resolve_settlement_currency(
    settle_coin: &str,
    base_currency: Currency,
    quote_currency: Currency,
) -> anyhow::Result<Currency> {
    if settle_coin.eq_ignore_ascii_case(base_currency.code.as_str()) {
        Ok(base_currency)
    } else if settle_coin.eq_ignore_ascii_case(quote_currency.code.as_str()) {
        Ok(quote_currency)
    } else {
        Err(anyhow::anyhow!(
            "unrecognized settlement currency '{settle_coin}'"
        ))
    }
}

/// Returns a currency from the internal map or creates a new crypto currency.
///
/// Uses [`Currency::get_or_create_crypto`] to handle unknown currency codes,
/// which automatically registers newly listed Bybit assets.
pub fn get_currency(code: &str) -> Currency {
    Currency::get_or_create_crypto(code)
}

fn extract_strike_from_symbol(symbol: &str) -> anyhow::Result<Price> {
    let parts: Vec<&str> = symbol.split('-').collect();
    let strike = parts
        .get(2)
        .ok_or_else(|| anyhow::anyhow!("invalid option symbol '{symbol}'"))?;

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Check the instrument's settleCoin in the Bybit response and confirm it is supported (base or quote of the symbol).
  2. Filter instruments on subscribe: only request symbols whose settleCoin matches base or quote.
  3. Upgrade the adapter if support for the new settlement currency (e.g. USDC) was added upstream.
  4. Extend resolve_settlement_currency to map the new settle coin to a registered Currency if it is legitimate for your use case.

Example fix

// before
let settle = resolve_settlement_currency(&settle_coin, base, quote)?;
// after
let supported = [base.code.as_str(), quote.code.as_str(), "USDT", "USDC"];
if !supported.iter().any(|c| settle_coin.eq_ignore_ascii_case(c)) {
    anyhow::bail!("skipping unsupported settle coin {settle_coin}");
}
let settle = resolve_settlement_currency(&settle_coin, base, quote)?;
Defensive patterns

Strategy: validation

Validate before calling

// Rust: filter instruments by supported settle coins before parsing
let supported = ["USDT", "USDC", base.code.as_str(), quote.code.as_str()];
let ok = inst.settle_coin.eq_ignore_ascii_case(base.code.as_str())
    || inst.settle_coin.eq_ignore_ascii_case(quote.code.as_str());

Type guard

fn settle_supported(settle_coin: &str, base: &Currency, quote: &Currency) -> bool {
    settle_coin.eq_ignore_ascii_case(base.code.as_str())
        || settle_coin.eq_ignore_ascii_case(quote.code.as_str())
}

Try / catch

match resolve_settlement_currency(&settle_coin, base, quote) {
    Ok(c) => c,
    Err(e) => { log::warn!("skipping instrument with settle coin {settle_coin}: {e:#}"); return Ok(None); }
};

Prevention

When it happens

Trigger: parse_linear_instrument or parse_inverse_instrument receives an instrument whose settleCoin (e.g. 'USDT', 'USDC', 'BTC') is case-insensitively neither the base nor quote currency of the symbol.

Common situations: New Bybit products (e.g. USDC-settled contracts) where settleCoin is not the traditional base/quote; symbols with unusual quote assets; stale symbol lists after delistings; unified-margin instruments not supported by the adapter version.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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