{"record":{"id":"df8b96e7cb742de6","repo":"nautechsystems/nautilus_trader","slug":"derive-candles-are-trade-based-only-pricetype-la","errorCode":null,"errorMessage":"Derive candles are trade-based; only PriceType::Last is supported (got {bar_type})","messagePattern":"Derive candles are trade-based; only PriceType::Last is supported \\(got (.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/derive/src/data.rs","lineNumber":1322,"sourceCode":"            ));\n\n            if let Err(e) = sender.send(DataEvent::Response(response)) {\n                log::error!(\"Failed to send Derive funding rates response: {e}\");\n            }\n            Ok(())\n        });\n\n        Ok(())\n    }\n\n    fn request_bars(&self, request: RequestBars) -> anyhow::Result<()> {\n        let bar_type = request.bar_type;\n        anyhow::ensure!(\n            bar_type.aggregation_source() == AggregationSource::External,\n            \"Derive only supports EXTERNAL aggregation source (got {bar_type})\",\n        );\n        let spec = bar_type.spec();\n        anyhow::ensure!(\n            spec.price_type == PriceType::Last,\n            \"Derive candles are trade-based; only PriceType::Last is supported (got {bar_type})\",\n        );\n\n        let instrument_id = bar_type.instrument_id();\n        let instrument = self\n            .instruments\n            .get_cloned(&instrument_id)\n            .ok_or_else(|| InstrumentLookupError::not_found(instrument_id))?;\n        let venue_symbol = format_venue_symbol(&instrument_id)?.to_string();\n        let price_precision = instrument.price_precision();\n        let size_precision = instrument.size_precision();\n\n        let period = bar_spec_to_derive_period(spec.aggregation, spec.step.get() as u64)\n            .with_context(|| format!(\"unsupported Derive bar spec for {bar_type}\"))?;\n\n        let http_client = self.http_client.clone();\n        let sender = self.data_sender.clone();","sourceCodeStart":1304,"sourceCodeEnd":1340,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/derive/src/data.rs#L1304-L1340","documentation":"Derive's candle endpoints are trade-based, so `request_bars` only accepts bars whose price type is `PriceType::Last`. Via `anyhow::ensure!` it rejects bar specs using bid/ask/mid/other price types, which Derive cannot source.","triggerScenarios":"Calling `request_bars` with a BarType whose `BarSpecification` price type is `Bid`, `Ask`, or `Mid` (e.g. 1-minute bid bars), which would need quote-based aggregation Derive does not provide.","commonSituations":"Strategy configs built for FX/quotes-driven venues requesting bid/ask bars; generic bar setup helpers defaulting to Mid; copying bar specs between adapters without adjusting price type.","solutions":["Change the bar specification's price type to `PriceType::Last`, e.g. `BarSpecification::new(1, BarAggregation::Minute, PriceType::Last)`.","Audit strategy config bar definitions and replace bid/ask/mid specs with last-trade specs.","If quote-based bars are needed, collect Derive quotes and aggregate internally rather than via request_bars.","Check the bar_type echoed in the error message to identify the offending spec quickly."],"exampleFix":"// before\nlet spec = BarSpecification::new(1, BarAggregation::Minute, PriceType::Mid);\n// after\nlet spec = BarSpecification::new(1, BarAggregation::Minute, PriceType::Last);","handlingStrategy":"validation","validationCode":"// Rust\nif bar_type.spec().price_type != PriceType::Last {\n    return Err(anyhow!(\"Derive bars require PriceType::Last: {bar_type}\"));\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = client.request_bars(req) {\n    if e.to_string().contains(\"PriceType::Last\") {\n        // rebuild spec with PriceType::Last\n    }\n}","preventionTips":["Always use PriceType::Last in Derive bar specifications.","Audit configs copied from bid/ask-driven venues.","Add a validation step that checks price type before requests.","Document adapter bar constraints next to strategy config schema."],"tags":["bars","price-type","derive","validation"],"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-14T00:17:10.932Z"}