{"record":{"id":"5723bc6e470c16e9","repo":"nautechsystems/nautilus_trader","slug":"binance-historical-bars-require-last-price-type-5723bc","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/spot/data.rs","lineNumber":2360,"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\") {\n                Ok(bars) => {\n                    let response = DataResponse::Bars(BarsResponse::new(\n                        request_id,\n                        client_id,\n                        bar_type,\n                        bars,","sourceCodeStart":2342,"sourceCodeEnd":2378,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/crates/adapters/binance/src/spot/data.rs#L2342-L2378","documentation":"Binance klines only record LAST-trade prices; there is no historical source for MID, BID or ASK price types. The adapter validates bar_type.spec().price_type on every historical bar request and rejects anything but PriceType::Last so the venue never receives an unsatisfiable query.","triggerScenarios":"Calling request_bars with a price type other than LAST, e.g. 'BTCUSDT_BINANCE-1-MINUTE-MID-EXTERNAL' or 'BTCUSDT_BINANCE-1-HOUR-BID-EXTERNAL'. The ensure! at spot/data.rs:2360 fires synchronously.","commonSituations":"Strategies that trade quote-derived bars (MID) ported from venues or data providers that do serve mid-price history; configs generated from analytics tooling that defaults to MID.","solutions":["Use -LAST- price type for all historical Binance bar requests","If MID/BID/ASK bars are required, subscribe to QuoteTicks and aggregate locally with an INTERNAL bar type","Pre-validate bar_type.spec().price_type == PriceType::Last before requesting"],"exampleFix":"// before\nlet bar_type = BarType::from_str(\"BTCUSDT_BINANCE-1-MINUTE-MID-EXTERNAL\")?;\n\n// after\nlet bar_type = BarType::from_str(\"BTCUSDT_BINANCE-1-MINUTE-LAST-EXTERNAL\")?;","handlingStrategy":"validation","validationCode":"fn ensure_last_price(bar_type: &BarType) -> anyhow::Result<()> {\n    anyhow::ensure!(\n        bar_type.spec().price_type == PriceType::Last,\n        \"historical Binance bars need LAST price type, got {bar_type}\"\n    );\n    Ok(())\n}","typeGuard":"fn is_last_price_bar(bar_type: &BarType) -> bool {\n    bar_type.spec().price_type == PriceType::Last\n}","tryCatchPattern":null,"preventionTips":["Assume exchange bar history is last-price unless the venue documents otherwise","Derive MID/BID/ASK bars from quote streams locally, never from history requests","Add a startup assertion for every bar type the strategy will request historically"],"tags":["binance","spot","bars","price-type","validation"],"backgroundTag":"invalid-bar-specification","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}