nautechsystems/nautilus_trader · error · anyhow::Error

Unsupported bar aggregation/step combination: {aggregation:?

Error message

Unsupported bar aggregation/step combination: {aggregation:?}/{step}

What it means

IB historical bar sizes only support a fixed set of aggregation/step pairs (1s, 5s, ..., 1 Day, 1 Week, 1 Month). bar_type_to_ib_bar_size maps Nautilus BarAggregation/step to IB HistoricalBarSize and fails for any unsupported combination.

Source

Thrown at crates/adapters/interactive_brokers/src/data/convert.rs:72

        (BarAggregation::Minute, 5) => HistoricalBarSize::Min5,
        (BarAggregation::Minute, 10) => HistoricalBarSize::Min10,
        (BarAggregation::Minute, 15) => HistoricalBarSize::Min15,
        (BarAggregation::Minute, 20) => HistoricalBarSize::Min20,
        (BarAggregation::Minute, 30) => HistoricalBarSize::Min30,
        // Hours
        (BarAggregation::Hour, 1) => HistoricalBarSize::Hour,
        (BarAggregation::Hour, 2) => HistoricalBarSize::Hour2,
        (BarAggregation::Hour, 3) => HistoricalBarSize::Hour3,
        (BarAggregation::Hour, 4) => HistoricalBarSize::Hour4,
        (BarAggregation::Hour, 8) => HistoricalBarSize::Hour8,
        // Days
        (BarAggregation::Day, 1) => HistoricalBarSize::Day,
        // Weeks
        (BarAggregation::Week, 1) => HistoricalBarSize::Week,
        // Months
        (BarAggregation::Month, 1) => HistoricalBarSize::Month,
        _ => {
            anyhow::bail!("Unsupported bar aggregation/step combination: {aggregation:?}/{step}",);
        }
    };

    Ok(bar_size)
}

/// Convert Nautilus PriceType to IB WhatToShow.
#[must_use]
pub fn price_type_to_ib_what_to_show(price_type: PriceType) -> HistoricalWhatToShow {
    match price_type {
        PriceType::Last => HistoricalWhatToShow::Trades,
        PriceType::Bid => HistoricalWhatToShow::Bid,
        PriceType::Ask => HistoricalWhatToShow::Ask,
        PriceType::Mid => HistoricalWhatToShow::MidPoint,
        _ => HistoricalWhatToShow::Trades, // Default to trades
    }
}

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Use an IB-supported bar size: step 1 with Second/Minute/Hour/Day/Week/Month aggregations matching the adapter's supported set
  2. Aggregate locally: request the smallest supported IB bar size and build the desired bars client-side
  3. Check the mapping table in bar_type_to_ib_bar_size to confirm the exact supported pairs

Example fix

// before
let bar_type = BarType::from("AAPL.SMART-2-HOUR-LAST-EXTERNAL");
// after
let bar_type = BarType::from("AAPL.SMART-1-HOUR-LAST-EXTERNAL"); // aggregate 2h locally if needed
Defensive patterns

Strategy: validation

Validate before calling

fn ib_bar_supported(aggregation: BarAggregation, step: u32) -> bool {
    matches!(
        (aggregation, step),
        (BarAggregation::Second, 1 | 5 | 10 | 15 | 30)
            | (BarAggregation::Minute, 1 | 2 | 3 | 5 | 10 | 15 | 20 | 30)
            | (BarAggregation::Hour, 1 | 2 | 3 | 4 | 8)
            | (BarAggregation::Day, 1)
            | (BarAggregation::Week, 1)
            | (BarAggregation::Month, 1)
    )
}

Try / catch

match bar_type_to_ib_bar_size(&bar_type) {
    Ok(size) => size,
    Err(e) if e.to_string().contains("Unsupported bar aggregation") => {
        tracing::warn!("{} not supported by IB; falling back to 1-minute bars", bar_type);
        bar_type_to_ib_bar_size(&fallback_bar_type)?
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling request_bars with a BarType aggregated by something other than Second/Minute/Hour/Day/Week/Month with step 1 — e.g. Minute with step 5? (check the map: Minute/1 etc.) or unsupported steps like 2-day or 15-second bars when not in the mapping table.

Common situations: Requesting bars with non-unit steps (e.g. 2 Hour) or exotic aggregations (Tick, Value) that IB history does not offer.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/48811e06175c8d8f. Report an issue: GitHub.