nautechsystems/nautilus_trader · error · anyhow::Error

Unknown IB security type: {value}

Error message

Unknown IB security type: {value}

What it means

IbSecurityType's TryFrom conversion maps ibapi contract SecurityType values onto the adapter's enum. When the ibapi crate yields SecurityType::Other(value) — a security type the adapter does not recognize — the conversion bails with the raw string embedded in the message. This prevents unsupported IB contract types from entering the adapter as a wrong default.

Source

Thrown at crates/adapters/interactive_brokers/src/common/enums/contracts.rs:136

    fn try_from(value: &ibapi::contracts::SecurityType) -> Result<Self, Self::Error> {
        match value {
            ibapi::contracts::SecurityType::Stock => Ok(Self::Stock),
            ibapi::contracts::SecurityType::Option => Ok(Self::Option),
            ibapi::contracts::SecurityType::Future => Ok(Self::Future),
            ibapi::contracts::SecurityType::ContinuousFuture => Ok(Self::ContinuousFuture),
            ibapi::contracts::SecurityType::Index => Ok(Self::Index),
            ibapi::contracts::SecurityType::FuturesOption => Ok(Self::FuturesOption),
            ibapi::contracts::SecurityType::ForexPair => Ok(Self::ForexPair),
            ibapi::contracts::SecurityType::Spread => Ok(Self::Spread),
            ibapi::contracts::SecurityType::Warrant => Ok(Self::Warrant),
            ibapi::contracts::SecurityType::Bond => Ok(Self::Bond),
            ibapi::contracts::SecurityType::Commodity => Ok(Self::Commodity),
            ibapi::contracts::SecurityType::News => Ok(Self::News),
            ibapi::contracts::SecurityType::MutualFund => Ok(Self::MutualFund),
            ibapi::contracts::SecurityType::Crypto => Ok(Self::Crypto),
            ibapi::contracts::SecurityType::CFD => Ok(Self::Cfd),
            ibapi::contracts::SecurityType::Other(value) => {
                anyhow::bail!("Unknown IB security type: {value}")
            }
        }
    }
}

impl FromStr for IbSecurityType {
    type Err = anyhow::Error;

    fn from_str(value: &str) -> Result<Self, Self::Err> {
        match value.to_ascii_uppercase().as_str() {
            "STK" => Ok(Self::Stock),
            "OPT" => Ok(Self::Option),
            "FUT" => Ok(Self::Future),
            "CONTFUT" => Ok(Self::ContinuousFuture),
            "IND" => Ok(Self::Index),
            "FOP" => Ok(Self::FuturesOption),
            "CASH" => Ok(Self::ForexPair),
            "BAG" => Ok(Self::Spread),

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Use a supported security type (Stock, Option, Future, Forex, Index, Cfd, Crypto, etc.) for the contract.
  2. Add a mapping arm for the unsupported IB security type in the TryFrom impl if the adapter should support it.
  3. Validate/whitelist the secType string before building the contract, failing with a clearer user-facing message.
  4. Check ibapi crate version compatibility; a new enum variant may need adapter support.

Example fix

// before
let sec_type = IbSecurityType::try_from(ib_contract.sec_type)?;
// after
let sec_type = match IbSecurityType::try_from(ib_contract.sec_type) {
    Ok(t) => t,
    Err(e) => {
        tracing::warn!("skipping contract with {e}");
        return Ok(None);
    }
};
Defensive patterns

Strategy: type-guard

Validate before calling

fn is_supported_sec_type(s: &str) -> bool {
    matches!(s, "STK" | "OPT" | "FUT" | "CASH" | "IND" | "COM" | "NEWS"
        | "FUND" | "CRYPTO" | "CFD")
}

Type guard

fn as_supported(t: &ibapi::contracts::SecurityType) -> Option<IbSecurityType> {
    IbSecurityType::try_from(t.clone()).ok()
}

Try / catch

let sec_type = match IbSecurityType::try_from(contract.sec_type) {
    Ok(t) => t,
    Err(e) => {
        tracing::warn!("unsupported contract skipped: {e}");
        return Ok(None);
    }
};

Prevention

When it happens

Trigger: Converting an IB contract's security type that is not one of the explicitly handled variants (Stock, Option, Futures, Forex, Index, Commodity, News, MutualFund, Crypto, CFD, etc.), e.g. when subscribing to or describing a contract whose secType the adapter hasn't mapped.

Common situations: Using exotic/less-common IB products (warrants, bonds, rights, spread contracts) whose secType maps to Other; a newer ibapi crate version introducing types the adapter doesn't cover; wiring up user-supplied secType strings not validated before conversion.

Related errors


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