nautechsystems/nautilus_trader · error · anyhow::Error

historical BinanceBar requests require time aggregation

Error message

historical BinanceBar requests require time aggregation

What it means

NautilusTrader's Binance Futures data client refuses historical bar requests unless the bar type uses externally aggregated, time-based bars of LAST price type, because Binance's REST kline endpoint is the only supported source and it returns time-binned trades. This ensure! guards request_data so unsupported bar specs fail fast with a clear message instead of producing wrong or empty data.

Solutions

  1. Change the BarType to EXTERNAL aggregation, e.g. BarType.from_str('BTCUSDT-PERP.BINANCE-1-MINUTE-LAST-EXTERNAL')
  2. Ensure price_type is PriceType.LAST in the bar spec
  3. Use a time-based aggregation (SECOND/MINUTE/HOUR/DAY spec) instead of tick/volume/dollar aggregation
  4. If you need internal aggregation, generate bars from streamed trades/ticks instead of requesting historical bars

Example fix

// before
let bar_type = BarType::from_str("BTCUSDT-PERP.BINANCE-100-TICK-LAST-INTERNAL")?;
// after
let bar_type = BarType::from_str("BTCUSDT-PERP.BINANCE-1-MINUTE-LAST-EXTERNAL")?;
Defensive patterns

Strategy: validation

Validate before calling

fn valid_historical_bar_type(bar_type: &BarType) -> bool {
    bar_type.aggregation_source() == AggregationSource::External
        && bar_type.spec().price_type == PriceType::Last
        && bar_type.spec().is_time_aggregated()
}

Try / catch

match client.request_data(request) {
    Err(e) if e.to_string().contains("require") => eprintln!("unsupported bar type: {e}"),
    Err(e) => return Err(e),
    Ok(_) => {},
}

Prevention

When it happens

Trigger: Calling DataEngine.request(BarsRequest) (or a historical request via the Binance Futures data client) with a BarType whose aggregation_source is Internal (Nautilus aggregating from trades/ticks), whose price_type is not Last (e.g. Bid/Ask/Mid), or whose aggregation is tick/volume/dollar-based rather than time-based (e.g. 100-tick bars).

Common situations: Users configure bar types like 'BTCUSDT-PERP.BINANCE-100-TICK-LAST-INTERNAL' or bid/ask bars, then request historical data. Works in live streaming (internal aggregation) but fails on historical lookup because Binance cannot serve it.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at crates/adapters/binance/src/futures/data.rs:2686

    /// Requests Binance futures custom data.
    ///
    /// Spawned fetch failures are logged and no response is emitted, matching
    /// the existing request-path behavior for other Binance adapter requests.
    fn request_data(&self, request: RequestCustomData) -> anyhow::Result<()> {
        let data_type = request.data_type.clone();
        let data_type_name = data_type.type_name().to_string();

        if data_type_name == "BinanceBar" {
            let bar_type = parse_binance_bar_type(&data_type)?;
            anyhow::ensure!(
                bar_type.aggregation_source() == AggregationSource::External,
                "historical BinanceBar requests require EXTERNAL aggregation"
            );
            anyhow::ensure!(
                bar_type.spec().price_type == PriceType::Last,
                "historical BinanceBar requests require LAST price type"
            );
            anyhow::ensure!(
                bar_type.spec().is_time_aggregated(),
                "historical BinanceBar requests require time aggregation"
            );
            let http = self.http_client.clone();
            let sender = self.data_sender.clone();
            let request_id = request.request_id;
            let client_id = request.client_id;
            let start = request.start;
            let end = request.end;
            let limit = request.limit.map(|value| value.get() as u32);
            let params = request.params;
            let clock = self.clock;
            let venue = self.venue();
            let start_nanos = datetime_to_unix_nanos(start);
            let end_nanos = datetime_to_unix_nanos(end);
            self.spawn_command(async move {
                match http.request_binance_bars(bar_type, start, end, limit).await {
                    Ok(bars) => {

View on GitHub (pinned to 18893faf8b)