nautechsystems/nautilus_trader · error

Unsupported hour interval

Error message

Unsupported hour interval: {step}h

What it means

bar_spec_to_binance_interval converts a Nautilus BarAggregation/step pair into a Binance kline interval. Binance only supports specific hour klines (1h, 2h, 4h, 6h, 8h, 12h), so an hour-aggregated bar spec with any other step cannot be mapped and the function bails with this error before subscribing.

Solutions

  1. Change the bar spec step to one of 1, 2, 4, 6, 8, or 12 hours
  2. Aggregate internally: request a supported interval (e.g. 1h) and build 3h bars via internal aggregation if needed
  3. If you own the parse code, extend the match arms only if Binance adds new kline intervals

Example fix

// before
BarSpec::new(instrument_id, BAR_SPEC_3_HOUR, PriceType::Last)
// after
BarSpec::new(instrument_id, BAR_SPEC_4_HOUR, PriceType::Last)
Defensive patterns

Strategy: validation

Validate before calling

const SUPPORTED_HOURS: [u64; 6] = [1, 2, 4, 6, 8, 12];
fn is_supported_hour_step(step: u64) -> bool { SUPPORTED_HOURS.contains(&step) }
if !is_supported_hour_step(bar_spec.aggregation_step) { /* fix spec before subscribe_bars */ }

Type guard

fn is_supported_hour_step(step: u64) -> bool { matches!(step, 1 | 2 | 4 | 6 | 8 | 12) }

Try / catch

match client.subscribe_bars(bar_spec) {
    Err(e) if e.to_string().contains("Unsupported hour interval") => {
        log::warn!("falling back to 1h bars with internal aggregation");
    }
    r => r?,
}

Prevention

When it happens

Trigger: Calling subscribe_bars or unsubscribe_bars with a BarAggregation::Hour step not in {1,2,4,6,8,12}, e.g. a 3-HOUR or 5-HOUR bar spec on a Binance data client.

Common situations: Configuring a custom 3h or 5h bar aggregation in a strategy config and assuming Binance supports arbitrary hour steps; migrating from another venue whose API supports arbitrary intervals.

Related errors


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

Appendix: source

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

            1 => BinanceKlineInterval::Second1,
            _ => anyhow::bail!("Unsupported second interval: {step}s"),
        },
        BarAggregation::Minute => match step {
            1 => BinanceKlineInterval::Minute1,
            3 => BinanceKlineInterval::Minute3,
            5 => BinanceKlineInterval::Minute5,
            15 => BinanceKlineInterval::Minute15,
            30 => BinanceKlineInterval::Minute30,
            _ => anyhow::bail!("Unsupported minute interval: {step}m"),
        },
        BarAggregation::Hour => match step {
            1 => BinanceKlineInterval::Hour1,
            2 => BinanceKlineInterval::Hour2,
            4 => BinanceKlineInterval::Hour4,
            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)

View on GitHub (pinned to 18893faf8b)