nautechsystems/nautilus_trader · error
Invalid bar type string: '{bt}'
Error message
Invalid bar type string: '{bt}' What it means
BacktestConfig derives instrument IDs from its configured bar_types by parsing each string into a BarType. If any string is not a valid BarType representation, the parse fails and this error reports the offending string. BarType strings must encode instrument id, step, aggregation, and source (e.g. 'EUR/USD.SIM-1-MINUTE-EXTERNAL').
Source
Thrown at crates/backtest/src/config.rs:1029
/// # Errors
///
/// Returns an error if any bar type string cannot be parsed.
pub fn get_instrument_ids(&self) -> anyhow::Result<Vec<InstrumentId>> {
if let Some(id) = self.instrument_id {
return Ok(vec![id]);
}
if let Some(ids) = &self.instrument_ids {
return Ok(ids.clone());
}
if let Some(bar_types) = &self.bar_types {
let ids = bar_types
.iter()
.map(|bt| {
bt.parse::<BarType>()
.map(|b| b.instrument_id())
.map_err(|_| anyhow::anyhow!("Invalid bar type string: '{bt}'"))
})
.collect::<anyhow::Result<Vec<_>>>()?;
return Ok(ids);
}
Ok(Vec::new())
}
}
/// Represents the configuration for one specific backtest run.
/// This includes a backtest engine with its actors and strategies, with the external inputs of venues and data.
#[derive(Debug, Clone, bon::Builder)]
#[builder(finish_fn(name = build_inner, vis = ""))]
#[cfg_attr(
feature = "python",
pyo3::pyclass(module = "nautilus_trader.backtest", from_py_object, unsendable)
)]
#[cfg_attr(
feature = "python",View on GitHub (pinned to 18893faf8b)
Solutions
- Fix the offending bar_types string to a full BarType format like 'INSTRUMENT.VENUE-<step>-<AGGREGATION>-<SOURCE>' (e.g. 'AAPL.NASDAQ-1-MINUTE-EXTERNAL').
- Build bar types programmatically via BarType::new / from components instead of hand-writing strings.
- Validate each bar_types entry by parsing it in your config loader and logging the exact parse error for diagnosis.
Example fix
// before bar_types = ["AAPL.NASDAQ-1-MIN"] // after bar_types = ["AAPL.NASDAQ-1-MINUTE-EXTERNAL"]
Defensive patterns
Strategy: validation
Validate before calling
// validate bar type strings before building config
for bt in &bar_types {
if let Err(e) = bt.parse::<BarType>() {
return Err(format!("invalid bar_types entry '{bt}': {e}"));
}
} Prevention
- Use BarType::parse in a config preflight step and surface the underlying parse error.
- Construct bar types programmatically instead of hand-writing strings.
- Keep a documented example of the exact format INSTRUMENT.VENUE-step-AGGREGATION-SOURCE.
When it happens
Trigger: Calling the config method that resolves bar instruments (instrument_ids_for_bars) while self.bar_types contains a string that fails bt.parse::<BarType>() — malformed separators, wrong aggregation keyword, unknown source, or an instrument id that doesn't parse as InstrumentId.
Common situations: Hand-written backtest config YAML/JSON with a typo like '1-MIN' instead of '1-MINUTE'; missing the -EXTERNAL suffix; wrong venue/instrument formatting; bar types copied from a different adapter's naming convention.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Unsupported Deribit resolution: {resolution}
- Invalid Hyperliquid bar interval: {s}
- Invalid timeframe for `BarSpecification`, was {timeframe}
- Invalid `NautilusDataType`: '{s}'
- invalid Futures kline {}: {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/3e26f91f82e3caa6.
Report an issue: GitHub.