{"record":{"id":"fc745726de4dd2c4","repo":"nautechsystems/nautilus_trader","slug":"binance-historical-bars-require-last-price-type","errorCode":null,"errorMessage":"Binance historical bars require LAST price type","messagePattern":"Binance historical bars require LAST price type","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/futures/data.rs","lineNumber":3006,"sourceCode":"\n    fn request_bars(&self, request: RequestBars) -> anyhow::Result<()> {\n        let http = self.http_client.clone();\n        let sender = self.data_sender.clone();\n        let bar_type = request.bar_type;\n        let start = request.start;\n        let end = request.end;\n        let limit = request.limit.map(|n| n.get() as u32);\n        let request_id = request.request_id;\n        let client_id = request.client_id.unwrap_or(self.client_id);\n        let params = request.params;\n        let clock = self.clock;\n        let start_nanos = datetime_to_unix_nanos(start);\n        let end_nanos = datetime_to_unix_nanos(end);\n        anyhow::ensure!(\n            bar_type.aggregation_source() == AggregationSource::External,\n            \"Binance historical bars require EXTERNAL aggregation\"\n        );\n        anyhow::ensure!(\n            bar_type.spec().price_type == PriceType::Last,\n            \"Binance historical bars require LAST price type\"\n        );\n        anyhow::ensure!(\n            bar_type.spec().is_time_aggregated(),\n            \"Binance historical bars require time aggregation\"\n        );\n\n        get_runtime().spawn(async move {\n            let result = http.request_bars(bar_type, start, end, limit).await;\n\n            match result.context(\"failed to request bars from Binance Futures\") {\n                Ok(bars) => {\n                    let response = DataResponse::Bars(BarsResponse::new(\n                        request_id,\n                        client_id,\n                        bar_type,\n                        bars,","sourceCodeStart":2988,"sourceCodeEnd":3024,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/crates/adapters/binance/src/futures/data.rs#L2988-L3024","documentation":"The standard historical-bars request path only serves LAST-price bars: after the EXTERNAL aggregation check it enforces `PriceType::Last`. Binance klines are last-trade candles, so MID/BID/ASK bar types are rejected before the HTTP fetch is spawned.","triggerScenarios":"`request_bars` with a BarType such as `BTCUSDT-PERP.BINANCE-1-MINUTE-MID-EXTERNAL`, `-BID-EXTERNAL`, or `-ASK-EXTERNAL`. (Price type is checked after aggregation source, so an INTERNAL MID bar fails with the aggregation error first.)","commonSituations":"Strategies standardised on MID bars across venues; generic backfill code requesting whatever bar types a config lists; assuming quote-price klines exist on Binance.","solutions":["Request a LAST bar type, e.g. `BTCUSDT-PERP.BINANCE-1-MINUTE-LAST-EXTERNAL`","For quote-price bars, collect book/quote data and aggregate locally instead of requesting Binance history"],"exampleFix":"# before\nbar_type = BarType.from_str('BTCUSDT-PERP.BINANCE-1-MINUTE-MID-EXTERNAL')\n\n# after\nbar_type = BarType.from_str('BTCUSDT-PERP.BINANCE-1-MINUTE-LAST-EXTERNAL')","handlingStrategy":"validation","validationCode":"from nautilus_trader.model.enums import PriceType\n\ndef is_requestable_binance_bar(bar_type) -> bool:\n    return bar_type.spec.price_type == PriceType.LAST\n\nif not is_requestable_binance_bar(request_bar_type):\n    raise ValueError(f'{request_bar_type} is {request_bar_type.spec.price_type}; Binance kline history is LAST only')","typeGuard":"def is_last_price_bar(bar_type) -> bool:\n    return bar_type.spec.price_type == PriceType.LAST","tryCatchPattern":"try:\n    actor.request_bars(bar_type, start=start_ts, end=end_ts)\nexcept Exception as e:\n    if 'require LAST price type' in str(e):\n        raise ValueError('Request the -LAST- bar type for Binance history; build quote-price bars locally from book data') from e\n    raise","preventionTips":["Standardise Binance bar configs on LAST price; MID/BID/ASK klines are unavailable from the exchange","Validate price type together with aggregation source before any history request"],"tags":["binance","futures","bars","price-type","request-validation"],"backgroundTag":"bar-price-type-not-last","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}