nautechsystems/nautilus_trader · error

Invalid `NautilusDataType`: '{s}'

Error message

Invalid `NautilusDataType`: '{s}'

What it means

NautilusDataType implements FromStr so config values given as strings (e.g. from TOML/CLI) can be parsed into the enum. This error is thrown when the string does not exactly match any variant name — parsing is case-sensitive and uses the Rust variant identifiers (e.g. "TradeTick", not "trade_tick" or "TradeTicks").

Source

Thrown at crates/backtest/src/config.rs:96

}

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

    fn from_str(s: &str) -> anyhow::Result<Self> {
        match s {
            stringify!(QuoteTick) => Ok(Self::QuoteTick),
            stringify!(TradeTick) => Ok(Self::TradeTick),
            stringify!(Bar) => Ok(Self::Bar),
            stringify!(OrderBookDelta) => Ok(Self::OrderBookDelta),
            stringify!(OrderBookDepth10) => Ok(Self::OrderBookDepth10),
            stringify!(MarkPriceUpdate) => Ok(Self::MarkPriceUpdate),
            stringify!(IndexPriceUpdate) => Ok(Self::IndexPriceUpdate),
            stringify!(FundingRateUpdate) => Ok(Self::FundingRateUpdate),
            stringify!(InstrumentStatus) => Ok(Self::InstrumentStatus),
            stringify!(OptionGreeks) => Ok(Self::OptionGreeks),
            stringify!(InstrumentClose) => Ok(Self::InstrumentClose),
            _ => anyhow::bail!("Invalid `NautilusDataType`: '{s}'"),
        }
    }
}

/// Configuration for ``BacktestEngine`` instances.
#[cfg_attr(
    feature = "python",
    pyo3::pyclass(module = "nautilus_trader.backtest", from_py_object, unsendable)
)]
#[cfg_attr(
    feature = "python",
    pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.backtest")
)]
#[expect(
    clippy::struct_excessive_bools,
    reason = "config fields mirror the existing Rust and Python backtest engine surfaces"
)]
#[derive(Debug, Clone, bon::Builder)]

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Use the exact variant name with correct casing, e.g. "TradeTick", "QuoteTick", "OrderBookDeltas"
  2. Check the enum definition in crates/backtest/src/config.rs for valid variant names
  3. Strip whitespace and fix casing in the config source
  4. If migrating from Python configs, convert snake_case values to PascalCase variant names

Example fix

// before
let dt: NautilusDataType = "trade_tick".parse()?;  // invalid
// after
let dt: NautilusDataType = "TradeTick".parse()?;
Defensive patterns

Strategy: validation

Validate before calling

const VALID: &[&str] = &["TradeTick","QuoteTick","OrderBookDeltas","OrderBookDepth10","OrderBookDeltas1s","InstrumentClose","MarkPriceUpdate","IndexPriceUpdate","FundingRateUpdate","InstrumentStatus","OptionGreeks"];
fn valid_dtype(s: &str) -> Result<NautilusDataType, String> {
    s.trim().parse::<NautilusDataType>()
        .map_err(|_| format!("'{s}' is not a NautilusDataType variant; try PascalCase like 'TradeTick'"))
}

Try / catch

let dt = "trade_tick".parse::<NautilusDataType>()
    .map_err(|e| anyhow::anyhow!("bad backtest config data_type: {e}; use PascalCase variant names"))?;

Prevention

When it happens

Trigger: Parsing a NautilusDataType from a string in a backtest config where the value is misspelled, wrongly cased, or uses snake_case (e.g. "quote_tick" instead of "QuoteTick").

Common situations: Hand-editing a TOML/JSON backtest config; porting configs from Python (snake_case) into Rust; typo like "TradeTick " with whitespace or "quote" abbreviation.

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