nautechsystems/nautilus_trader · error · anyhow::Error

Unknown IB option right: {value}

Error message

Unknown IB option right: {value}

What it means

IbOptionRight::from_str parses an IB option right string into the adapter's Call/Put enum. Values other than "C"/"CALL"/"P"/"PUT" (case-insensitive, input is uppercased first) hit the bail. It guards against malformed or unmapped IB `right` fields on option contracts.

Source

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

    /// Converts this option right to a Nautilus option kind.
    #[must_use]
    pub const fn option_kind(self) -> OptionKind {
        match self {
            Self::Call => OptionKind::Call,
            Self::Put => OptionKind::Put,
        }
    }
}

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

    fn from_str(value: &str) -> Result<Self, Self::Err> {
        match value.to_ascii_uppercase().as_str() {
            "C" | "CALL" => Ok(Self::Call),
            "P" | "PUT" => Ok(Self::Put),
            _ => anyhow::bail!("Unknown IB option right: {value}"),
        }
    }
}

impl Display for IbOptionRight {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Check the contract is actually an option (secType OPT/FOP) before parsing its `right` field; skip or handle non-option contracts separately.
  2. Correct the value to "C"/"CALL" or "P"/"PUT" (any casing works, e.g. "c", "Put").
  3. If IB returns a right code the adapter should support, add it to the match in crates/adapters/interactive_brokers/src/common/enums/contracts.rs.

Example fix

// before
let right: IbOptionRight = contract.right.parse()?; // right == "?" for stocks
// after
let right = if matches!(contract.sec_type.as_str(), "OPT" | "FOP") {
    Some(contract.right.parse::<IbOptionRight>()?)
} else {
    None
};
Defensive patterns

Strategy: type-guard

Validate before calling

fn parseable_option_right(v: &str) -> bool {
    matches!(v.to_ascii_uppercase().as_str(), "C" | "CALL" | "P" | "PUT")
}

Type guard

fn as_ib_option_right(v: &str) -> Option<IbOptionRight> {
    use std::str::FromStr;
    IbOptionRight::from_str(v).ok()
}

Try / catch

match contract.right.parse::<IbOptionRight>() {
    Ok(right) => handle(right),
    Err(e) => { log::debug!("non-option contract (right={:?}): {e}", contract.right); }
}

Prevention

When it happens

Trigger: Parsing an IB Contract's `right` field that is not a call/put designator — e.g. "?" (returned by IB for non-option contracts), empty string, or code passing a full name like "Call" with different text variants; direct IbOptionRight::from_str/parse calls with an unexpected value.

Common situations: Iterating IB positions or contract details where non-option instruments carry right="?" or "" and the code parses the right unconditionally; options on futures or other structured products using unusual right codes; hand-written instrument configs with misspelled rights.

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/18f17b5c022db330. Report an issue: GitHub.