nautechsystems/nautilus_trader · error

Unsupported bar aggregation for Binance

Error message

Unsupported bar aggregation for Binance: {agg:?}

What it means

The catch-all arm of bar_spec_to_binance_interval: the BarAggregation variant itself is not mapped for Binance at all (e.g. Tick or Volume aggregation), not just an unsupported step. Binance klines only exist for time-based intervals, so non-time aggregations cannot be converted.

Solutions

  1. Use a time-based BarAggregation (Second, Minute, Hour, Day, Week, Month) with a supported step
  2. Route tick/volume bar specs to a data engine configured for internal aggregation
  3. Verify the BarSpec aggregation before handing it to the Binance factory

Example fix

// before
BarSpec::new(instrument_id, BAR_SPEC_100_TICKS, PriceType::Last)
// after
BarSpec::new(instrument_id, BAR_SPEC_1_MINUTE_LAST, PriceType::Last)
Defensive patterns

Strategy: validation

Validate before calling

use nautilus_model::enums::BarAggregation;
fn is_time_based(agg: BarAggregation) -> bool {
    matches!(agg, BarAggregation::Second | BarAggregation::Minute | BarAggregation::Hour | BarAggregation::Day | BarAggregation::Week | BarAggregation::Month)
}

Type guard

fn is_time_based(agg: BarAggregation) -> bool {
    matches!(agg, BarAggregation::Second | BarAggregation::Minute | BarAggregation::Hour | BarAggregation::Day | BarAggregation::Week | BarAggregation::Month)
}

Try / catch

match client.subscribe_bars(bar_spec) {
    Err(e) if e.to_string().contains("Unsupported bar aggregation for Binance") => {
        panic!("Binance klines are time-based only; reconfigure bar spec: {e}");
    }
    r => r?,
}

Prevention

When it happens

Trigger: subscribe_bars or unsubscribe_bars with a non-time BarAggregation such as Tick or Volume, e.g. a TICK_COUNT or VOLUME bar spec sent to a Binance client.

Common situations: Reusing one strategy config across venues where the original venue supported tick/volume bars; accidentally wiring a Binance data client to a bar spec designed for a tick-data adapter.

Related errors


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

Appendix: source

Thrown at crates/adapters/binance/src/common/parse.rs:1463

            6 => BinanceKlineInterval::Hour6,
            8 => BinanceKlineInterval::Hour8,
            12 => BinanceKlineInterval::Hour12,
            _ => anyhow::bail!("Unsupported hour interval: {step}h"),
        },
        BarAggregation::Day => match step {
            1 => BinanceKlineInterval::Day1,
            3 => BinanceKlineInterval::Day3,
            _ => anyhow::bail!("Unsupported day interval: {step}d"),
        },
        BarAggregation::Week => match step {
            1 => BinanceKlineInterval::Week1,
            _ => anyhow::bail!("Unsupported week interval: {step}w"),
        },
        BarAggregation::Month => match step {
            1 => BinanceKlineInterval::Month1,
            _ => anyhow::bail!("Unsupported month interval: {step}M"),
        },
        agg => anyhow::bail!("Unsupported bar aggregation for Binance: {agg:?}"),
    };

    Ok(interval)
}

pub(crate) fn quote_to_l1_deltas(quote: QuoteTick, sequence: u64) -> OrderBookDeltas {
    let bid_action = if quote.bid_size.is_zero() {
        BookAction::Delete
    } else {
        BookAction::Update
    };
    let ask_action = if quote.ask_size.is_zero() {
        BookAction::Delete
    } else {
        BookAction::Update
    };
    let bid = OrderBookDelta::new(
        quote.instrument_id,

View on GitHub (pinned to 18893faf8b)