{"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":3052,"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        self.spawn_command(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":3034,"sourceCodeEnd":3070,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/futures/data.rs#L3034-L3070","documentation":"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.","triggerScenarios":"Requesting historical bars with a bar spec whose price_type is Bid, Ask, or Mid, e.g. 'BTCUSDT-PERP.BINANCE-1-MINUTE-BID-EXTERNAL'.","commonSituations":"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.","solutions":["Change the bar spec price_type to PriceType::Last, e.g. '...-1-MINUTE-LAST-EXTERNAL'","If you need bid/ask bars, aggregate them internally from streamed quote ticks instead of requesting them historically"],"exampleFix":"// before\nlet bar_type = BarType::from_str(\"BTCUSDT-PERP.BINANCE-1-MINUTE-BID-EXTERNAL\")?;\n// after\nlet bar_type = BarType::from_str(\"BTCUSDT-PERP.BINANCE-1-MINUTE-LAST-EXTERNAL\")?;","handlingStrategy":"validation","validationCode":"let ok = bar_type.spec().price_type == PriceType::Last;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default to LAST bars on Binance","Aggregate bid/ask/mid bars internally from quotes rather than requesting history"],"tags":["binance","bar-type","price-type","historical-data"],"backgroundTag":"invalid-enum-value","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}