nautechsystems/nautilus_trader · error · anyhow::Error

Binance historical bars require EXTERNAL aggregation

Error message

Binance historical bars require EXTERNAL aggregation

What it means

Binance historical bar requests can only be served from Binance's REST kline API, so the bar type must use AggregationSource::External (bars aggregated by the exchange). This ensure! in request_bars rejects internally aggregated bar types, which Nautilus would otherwise have to synthesize from historical trades.

Solutions

  1. Construct the BarType with AggregationSource::External for historical requests
  2. Use a bar-type string with the -EXTERNAL suffix, e.g. 'BTCUSDT-PERP.BINANCE-1-MINUTE-LAST-EXTERNAL'
  3. Keep separate BarTypes: internal for streaming, external for historical lookups

Example fix

// before
let bar_type = BarType::new(instrument_id, spec, AggregationSource::Internal);
// after
let bar_type = BarType::new(instrument_id, spec, AggregationSource::External);
Defensive patterns

Strategy: validation

Validate before calling

let ok = bar_type.aggregation_source() == AggregationSource::External;

Prevention

When it happens

Trigger: Requesting historical bars where the BarType was built with aggregation_source Internal (e.g. created programmatically with BarType::new(..., AggregationSource::Internal), or from a spec string without -EXTERNAL suffix, which defaults to internal in some APIs).

Common situations: Users build bar types for live streaming with internal aggregation (common for tick bars), then reuse the same BarType for a historical request; the historical lookup path rejects 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/ba6786af40d1aded. Report an issue: GitHub.

Appendix: source

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

        });

        Ok(())
    }

    fn request_bars(&self, request: RequestBars) -> anyhow::Result<()> {
        let http = self.http_client.clone();
        let sender = self.data_sender.clone();
        let bar_type = request.bar_type;
        let start = request.start;
        let end = request.end;
        let limit = request.limit.map(|n| n.get() as u32);
        let request_id = request.request_id;
        let client_id = request.client_id.unwrap_or(self.client_id);
        let params = request.params;
        let clock = self.clock;
        let start_nanos = datetime_to_unix_nanos(start);
        let end_nanos = datetime_to_unix_nanos(end);
        anyhow::ensure!(
            bar_type.aggregation_source() == AggregationSource::External,
            "Binance historical bars require EXTERNAL aggregation"
        );
        anyhow::ensure!(
            bar_type.spec().price_type == PriceType::Last,
            "Binance historical bars require LAST price type"
        );
        anyhow::ensure!(
            bar_type.spec().is_time_aggregated(),
            "Binance historical bars require time aggregation"
        );

        self.spawn_command(async move {
            let result = http.request_bars(bar_type, start, end, limit).await;

            match result.context("failed to request bars from Binance Futures") {
                Ok(bars) => {
                    let response = DataResponse::Bars(BarsResponse::new(

View on GitHub (pinned to 18893faf8b)