nautechsystems/nautilus_trader · error · anyhow::Error

Unknown IB action: {value}

Error message

Unknown IB action: {value}

What it means

IbAction::from_str converts an IB order action string (BUY, SELL, and legacy BOT/SLD/SSHORT/SLONG) into the adapter's enum. Any other action string bails. It validates order-side data coming from IB order objects or user order submissions before mapping to Nautilus OrderSide.

Source

Thrown at crates/adapters/interactive_brokers/src/common/enums/order.rs:96

            Self::Sell | Self::Sold => ibapi::orders::Action::Sell,
            Self::SellShort => ibapi::orders::Action::SellShort,
            Self::SellLong => ibapi::orders::Action::SellLong,
        }
    }
}

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

    fn from_str(value: &str) -> Result<Self, Self::Err> {
        match value {
            "BUY" => Ok(Self::Buy),
            "BOT" => Ok(Self::Bought),
            "SELL" => Ok(Self::Sell),
            "SLD" => Ok(Self::Sold),
            "SSHORT" => Ok(Self::SellShort),
            "SLONG" => Ok(Self::SellLong),
            _ => anyhow::bail!("Unknown IB action: {value}"),
        }
    }
}

impl From<ibapi::orders::Action> for IbAction {
    fn from(value: ibapi::orders::Action) -> Self {
        match value {
            ibapi::orders::Action::Buy => Self::Buy,
            ibapi::orders::Action::Sell => Self::Sell,
            ibapi::orders::Action::SellShort => Self::SellShort,
            ibapi::orders::Action::SellLong => Self::SellLong,
        }
    }
}

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

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Use exact uppercase IB action strings: "BUY" or "SELL" for standard orders (the legacy BOT/SLD forms are also accepted).
  2. If the value comes from an ibapi::orders::Action, convert with IbAction::from(value) instead of parsing its string.
  3. If you must support parity/spread actions ("P"/"C"), extend the match in crates/adapters/interactive_brokers/src/common/enums/order.rs or reject such orders upstream.

Example fix

// before
let action: IbAction = "buy".parse()?; // case-sensitive: fails
// after
let action: IbAction = "BUY".parse()?; // or
let action: IbAction = raw_action.to_ascii_uppercase().parse()?;
Defensive patterns

Strategy: type-guard

Validate before calling

fn is_valid_ib_action(v: &str) -> bool {
    matches!(v, "BUY" | "BOT" | "SELL" | "SLD" | "SSHORT" | "SLONG")
}

Type guard

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

Try / catch

match action_str.parse::<IbAction>() {
    Ok(a) => submit(a),
    Err(e) => { log::error!("refusing order with bad action {action_str:?}: {e}"); return OrderError::InvalidSide; }
}

Prevention

When it happens

Trigger: Parsing an ibapi order's `action` field containing a value outside {BUY, SELL, BOT, SLD, SSHORT, SLONG} — e.g. IB's "P" (parity) or "C" (cob) spread actions, empty strings, or user code calling IbAction::from_str with lowercase "buy" since this match is case-sensitive (no uppercase normalization shown in the arm list).

Common situations: Handling fill/order reports for combo or spread orders where IB uses single-letter parity actions instead of BUY/SELL; submitting orders through the adapter with a side string that isn't an exact uppercase IB action; strategy code mapping Nautilus OrderSide to strings with wrong casing.

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