nautechsystems/nautilus_trader · error · anyhow::Error

Binance historical bars require LAST price type

Error message

Binance historical bars require LAST price type

What it means

Binance's kline endpoint is derived from trade prices, so the Binance Futures data client only supports LAST trade-price bars for historical requests. This ensure! in request_bars rejects bar specs with Bid, Ask, or Mid price types because the exchange cannot provide them.

Solutions

  1. Change the bar spec price_type to PriceType::Last, e.g. '...-1-MINUTE-LAST-EXTERNAL'
  2. If you need bid/ask bars, aggregate them internally from streamed quote ticks instead of requesting them historically

Example fix

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

Strategy: validation

Validate before calling

let ok = bar_type.spec().price_type == PriceType::Last;

Prevention

When it happens

Trigger: Requesting historical bars with a bar spec whose price_type is Bid, Ask, or Mid, e.g. 'BTCUSDT-PERP.BINANCE-1-MINUTE-BID-EXTERNAL'.

Common situations: FX/crypto strategies using bid/ask bars copied from adapters backed by other venues (e.g. FX brokers) that do offer quote-based bars; running the same config against Binance fails on historical requests.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

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

    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(
                        request_id,
                        client_id,
                        bar_type,
                        bars,

View on GitHub (pinned to 18893faf8b)