nautechsystems/nautilus_trader · error · anyhow::Error

Unknown IB condition conjunction: {value}

Error message

Unknown IB condition conjunction: {value}

What it means

IbConditionConjunction::from_str in crates/adapters/interactive_brokers/src/common/enums/order.rs:823 parses how consecutive IB order conditions are joined ("and"/"a" or "or"/"o", case-insensitive) and bails with anyhow for any other value.

Source

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

            Self::Or => "or",
        }
    }

    /// Returns whether this conjunction is the rust-ibapi `is_conjunction` flag.
    #[must_use]
    pub const fn is_conjunction(self) -> bool {
        matches!(self, Self::And)
    }
}

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

    fn from_str(value: &str) -> Result<Self, Self::Err> {
        match value.to_ascii_lowercase().as_str() {
            "and" | "a" => Ok(Self::And),
            "or" | "o" => Ok(Self::Or),
            _ => anyhow::bail!("Unknown IB condition conjunction: {value}"),
        }
    }
}

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

/// Interactive Brokers price-condition trigger methods.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(
    feature = "python",
    pyo3::pyclass(
        module = "nautilus_trader.adapters.interactive_brokers",
        from_py_object,
        rename_all = "SCREAMING_SNAKE_CASE"

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Use "and"/"a" or "or"/"o" (case-insensitive).
  2. Map boolean/logic operators (&&, ||) to "and"/"or" before parsing.
  3. Trim whitespace and lowercase the input first.
  4. Extend the match arms upstream if more conjunction spellings are needed.

Example fix

// before
let c = "&&".parse::<IbConditionConjunction>()?; // bail!
// after
let c = "and".parse::<IbConditionConjunction>()?; // Ok(And)
Defensive patterns

Strategy: validation

Validate before calling

fn is_valid_conjunction(s: &str) -> bool {
    matches!(s.trim().to_ascii_lowercase().as_str(), "and" | "a" | "or" | "o")
}

Type guard

fn as_conjunction(s: &str) -> Option<IbConditionConjunction> {
    s.trim().to_ascii_lowercase().parse::<IbConditionConjunction>().ok()
}

Try / catch

match value.parse::<IbConditionConjunction>() {
    Ok(c) => join_conditions(c),
    Err(e) => log::error!("invalid conjunction '{value}' (expected and/a/or/o): {e}"),
}

Prevention

When it happens

Trigger: Parsing conjunction strings like "&&", "AND/OR", "nand", "both", or full words in other languages — anything outside {and, a, or, o} after lowercasing.

Common situations: Serializing conditions from a strategy DSL that uses "&&"/"||"; UI-driven config storing human text like "And then"; typos like "ad" or "orr".

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