{"record":{"id":"eae8e155b6650455","repo":"nautechsystems/nautilus_trader","slug":"invalid-barspecification-for-channel-was-bar-s","errorCode":null,"errorMessage":"Invalid `BarSpecification` for channel, was {bar_spec}","messagePattern":"Invalid `BarSpecification` for channel, was (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/okx/src/common/parse.rs","lineNumber":1404,"sourceCode":"        BAR_SPEC_3_MINUTE_LAST => OKXWsChannel::Candle3Minute,\n        BAR_SPEC_5_MINUTE_LAST => OKXWsChannel::Candle5Minute,\n        BAR_SPEC_15_MINUTE_LAST => OKXWsChannel::Candle15Minute,\n        BAR_SPEC_30_MINUTE_LAST => OKXWsChannel::Candle30Minute,\n        BAR_SPEC_1_HOUR_LAST => OKXWsChannel::Candle1Hour,\n        BAR_SPEC_2_HOUR_LAST => OKXWsChannel::Candle2Hour,\n        BAR_SPEC_4_HOUR_LAST => OKXWsChannel::Candle4Hour,\n        BAR_SPEC_6_HOUR_LAST => OKXWsChannel::Candle6Hour,\n        BAR_SPEC_12_HOUR_LAST => OKXWsChannel::Candle12Hour,\n        BAR_SPEC_1_DAY_LAST => OKXWsChannel::Candle1Day,\n        BAR_SPEC_2_DAY_LAST => OKXWsChannel::Candle2Day,\n        BAR_SPEC_3_DAY_LAST => OKXWsChannel::Candle3Day,\n        BAR_SPEC_5_DAY_LAST => OKXWsChannel::Candle5Day,\n        BAR_SPEC_1_WEEK_LAST => OKXWsChannel::Candle1Week,\n        BAR_SPEC_1_MONTH_LAST => OKXWsChannel::Candle1Month,\n        BAR_SPEC_3_MONTH_LAST => OKXWsChannel::Candle3Month,\n        BAR_SPEC_6_MONTH_LAST => OKXWsChannel::Candle6Month,\n        BAR_SPEC_12_MONTH_LAST => OKXWsChannel::Candle1Year,\n        _ => anyhow::bail!(\"Invalid `BarSpecification` for channel, was {bar_spec}\"),\n    };\n    Ok(channel)\n}\n\n/// Converts Nautilus bar specification to OKX mark price channel.\n///\n/// # Errors\n///\n/// Returns an error if the bar specification does not map to a mark price\n/// channel.\npub fn bar_spec_as_okx_mark_price_channel(\n    bar_spec: BarSpecification,\n) -> anyhow::Result<OKXWsChannel> {\n    let channel = match bar_spec {\n        BAR_SPEC_1_SECOND_LAST => OKXWsChannel::MarkPriceCandle1Second,\n        BAR_SPEC_1_MINUTE_LAST => OKXWsChannel::MarkPriceCandle1Minute,\n        BAR_SPEC_3_MINUTE_LAST => OKXWsChannel::MarkPriceCandle3Minute,\n        BAR_SPEC_5_MINUTE_LAST => OKXWsChannel::MarkPriceCandle5Minute,","sourceCodeStart":1386,"sourceCodeEnd":1422,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/okx/src/common/parse.rs#L1386-L1422","documentation":"bar_spec_as_okx_channel converts a Nautilus BarSpecification into the corresponding OKX websocket candle channel. OKX only supports a fixed set of candle intervals, so any bar specification outside the hardcoded BAR_SPEC_* table (step/aggregation/price-count bars, non-LAST bars, or unusual intervals like 2-day mark candles) is rejected with this message.","triggerScenarios":"Calling subscribe_bars or unsubscribe_bars with a BarType whose BarSpecification is not one of the supported LAST-price intervals (e.g. BarAggregation::Tick/Volume/Dollar bars, SECOND-second intervals, or an unsupported interval like 2D/4H that has no OKX candle channel).","commonSituations":"Configuring a strategy with generic Nautilus bar specs and assuming all map to OKX; copying a bar spec used on another adapter (Binance supports some intervals OKX does not); using mark-price candle specs (2D, 3M+) with the regular price channel which lacks those variants.","solutions":["Check the BarType's specification against the supported OKX candle list (1m..1D plus 2D/3D/5D/1W/1M/3M/6M/1Y, LAST price)","Change the requested bar spec to a supported interval, e.g. BAR_SPEC_1_MINUTE_LAST instead of a custom aggregation","If mark-price candles were intended, verify the spec is in bar_spec_as_okx_mark_price_channel's table (note it lacks 6M/12M and mark-specific variants)","Rebuild the bar aggregation locally from a supported OKX interval if custom aggregations are required"],"exampleFix":"// before\nlet bar_type = BarType::from_spec(instrument_id, BarSpecification::new(2, BarAggregation::Day, PriceType::Last));\ndata.subscribe_bars(bar_type); // bails: no Candle2Day price channel\n// after\nlet bar_type = BarType::from_spec(instrument_id, BAR_SPEC_1_DAY_LAST);\ndata.subscribe_bars(bar_type);","handlingStrategy":"validation","validationCode":"// only subscribe with supported OKX bar specs\nconst SUPPORTED: &[BarSpecification] = &[\n    BAR_SPEC_1_MINUTE_LAST, BAR_SPEC_1_HOUR_LAST, BAR_SPEC_1_DAY_LAST, BAR_SPEC_1_WEEK_LAST,\n];\nassert!(SUPPORTED.contains(&bar_type.spec()));","typeGuard":null,"tryCatchPattern":"match bar_spec_as_okx_channel(bar_type.spec()) {\n    Ok(channel) => subscribe(channel),\n    Err(e) => log::error!(\"bar spec not supported by OKX: {e}\"),\n}","preventionTips":["Restrict bar config to the OKX-supported interval table","Never reuse bar specs from other venue adapters without checking","Use BAR_SPEC_*_LAST constants shipped by the adapter"],"tags":["rust","okx","adapter","bars","websocket"],"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"}