{"record":{"id":"c8e50265bf9af5e4","repo":"nautechsystems/nautilus_trader","slug":"invalid-barspecification-for-timeframe-was-bar","errorCode":null,"errorMessage":"Invalid `BarSpecification` for timeframe, was {bar_spec}","messagePattern":"Invalid `BarSpecification` for timeframe, was (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/okx/src/common/parse.rs","lineNumber":1470,"sourceCode":"        BAR_SPEC_3_MINUTE_LAST => \"3m\",\n        BAR_SPEC_5_MINUTE_LAST => \"5m\",\n        BAR_SPEC_15_MINUTE_LAST => \"15m\",\n        BAR_SPEC_30_MINUTE_LAST => \"30m\",\n        BAR_SPEC_1_HOUR_LAST => \"1H\",\n        BAR_SPEC_2_HOUR_LAST => \"2H\",\n        BAR_SPEC_4_HOUR_LAST => \"4H\",\n        BAR_SPEC_6_HOUR_LAST => \"6H\",\n        BAR_SPEC_12_HOUR_LAST => \"12H\",\n        BAR_SPEC_1_DAY_LAST => \"1D\",\n        BAR_SPEC_2_DAY_LAST => \"2D\",\n        BAR_SPEC_3_DAY_LAST => \"3D\",\n        BAR_SPEC_5_DAY_LAST => \"5D\",\n        BAR_SPEC_1_WEEK_LAST => \"1W\",\n        BAR_SPEC_1_MONTH_LAST => \"1M\",\n        BAR_SPEC_3_MONTH_LAST => \"3M\",\n        BAR_SPEC_6_MONTH_LAST => \"6M\",\n        BAR_SPEC_12_MONTH_LAST => \"1Y\",\n        _ => anyhow::bail!(\"Invalid `BarSpecification` for timeframe, was {bar_spec}\"),\n    };\n    Ok(timeframe)\n}\n\n/// Converts OKX timeframe string to Nautilus bar specification.\n///\n/// # Errors\n///\n/// Returns an error if the timeframe string is not recognized.\npub fn okx_timeframe_as_bar_spec(timeframe: &str) -> anyhow::Result<BarSpecification> {\n    let bar_spec = match timeframe {\n        \"1s\" => BAR_SPEC_1_SECOND_LAST,\n        \"1m\" => BAR_SPEC_1_MINUTE_LAST,\n        \"3m\" => BAR_SPEC_3_MINUTE_LAST,\n        \"5m\" => BAR_SPEC_5_MINUTE_LAST,\n        \"15m\" => BAR_SPEC_15_MINUTE_LAST,\n        \"30m\" => BAR_SPEC_30_MINUTE_LAST,\n        \"1H\" => BAR_SPEC_1_HOUR_LAST,","sourceCodeStart":1452,"sourceCodeEnd":1488,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/okx/src/common/parse.rs#L1452-L1488","documentation":"bar_spec_as_okx_timeframe converts a Nautilus BarSpecification into the OKX REST timeframe string (e.g. \"1m\", \"1D\"). Any spec outside the fixed supported list — non-LAST price types or non-time aggregations — cannot be represented in OKX's timeframe vocabulary and is rejected with this message.","triggerScenarios":"Building an OKX REST bars request (via okx_bar_type_from_timeframe paths or history requests) with a BarSpecification such as a tick/volume/dollar bar, a bid/ask/mid price bar, or an interval OKX does not offer.","commonSituations":"Requesting historical bars with a spec imported from another venue's configuration; using PriceType::Bid/Ask bars believing OKX provides them (OKX candles are last-trade only); programmatic spec generation producing unsupported aggregations.","solutions":["Use one of the supported LAST-price time bars when constructing the BarType for OKX requests","Ensure PriceType::Last is set — bid/ask/mid specs are not supported by OKX candle endpoints","If alternative aggregations are needed, fetch a supported base interval and aggregate locally in Nautilus"],"exampleFix":"// before\nlet spec = BarSpecification::new(1, BarAggregation::Minute, PriceType::Bid);\nlet tf = bar_spec_as_okx_timeframe(&spec)?; // bails\n// after\nlet spec = BAR_SPEC_1_MINUTE_LAST;\nlet tf = bar_spec_as_okx_timeframe(&spec)?; // \"1m\"","handlingStrategy":"validation","validationCode":"if bar_type.spec().aggregation != BarAggregation::Minute\n    || bar_type.spec().price_type != PriceType::Last {\n    return Err(\"OKX requires LAST-price time bars\".into());\n}","typeGuard":null,"tryCatchPattern":"match bar_spec_as_okx_timeframe(&spec) {\n    Ok(tf) => request_bars(tf),\n    Err(e) => log::error!(\"unsupported bar spec for OKX REST: {e}\"),\n}","preventionTips":["Always use PriceType::Last for OKX bars","Avoid tick/volume/dollar aggregations in venue-bound requests; aggregate locally instead","Cross-check spec against okx_timeframe_as_bar_spec's round-trip table"],"tags":["rust","okx","adapter","bars","rest"],"backgroundTag":"unsupported-enum-value","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}