{"record":{"id":"386b9bd457355762","repo":"nautechsystems/nautilus_trader","slug":"invalid-timeframe-for-barspecification-was-tim","errorCode":null,"errorMessage":"Invalid timeframe for `BarSpecification`, was {timeframe}","messagePattern":"Invalid timeframe for `BarSpecification`, was (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/okx/src/common/parse.rs","lineNumber":1502,"sourceCode":"        \"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,\n        \"2H\" => BAR_SPEC_2_HOUR_LAST,\n        \"4H\" => BAR_SPEC_4_HOUR_LAST,\n        \"6H\" => BAR_SPEC_6_HOUR_LAST,\n        \"12H\" => BAR_SPEC_12_HOUR_LAST,\n        \"1D\" => BAR_SPEC_1_DAY_LAST,\n        \"2D\" => BAR_SPEC_2_DAY_LAST,\n        \"3D\" => BAR_SPEC_3_DAY_LAST,\n        \"5D\" => BAR_SPEC_5_DAY_LAST,\n        \"1W\" => BAR_SPEC_1_WEEK_LAST,\n        \"1M\" => BAR_SPEC_1_MONTH_LAST,\n        \"3M\" => BAR_SPEC_3_MONTH_LAST,\n        \"6M\" => BAR_SPEC_6_MONTH_LAST,\n        \"1Y\" => BAR_SPEC_12_MONTH_LAST,\n        _ => anyhow::bail!(\"Invalid timeframe for `BarSpecification`, was {timeframe}\"),\n    };\n    Ok(bar_spec)\n}\n\n/// Constructs a properly formatted BarType from OKX instrument ID and timeframe string.\n/// This ensures the BarType uses canonical Nautilus format instead of raw OKX strings.\n///\n/// # Errors\n///\n/// Returns an error if the timeframe cannot be converted into a\n/// `BarSpecification`.\npub fn okx_bar_type_from_timeframe(\n    instrument_id: InstrumentId,\n    timeframe: &str,\n) -> anyhow::Result<BarType> {\n    let bar_spec = okx_timeframe_as_bar_spec(timeframe)?;\n    Ok(BarType::new(\n        instrument_id,","sourceCodeStart":1484,"sourceCodeEnd":1520,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/okx/src/common/parse.rs#L1484-L1520","documentation":"okx_timeframe_as_bar_spec is the inverse mapping from an OKX timeframe string (\"1m\", \"4H\", \"1D\", ...) to a Nautilus BarSpecification. An unrecognized string means the code received a timeframe OKX emitted or a caller supplied that is outside the supported table, so it bails with this message.","triggerScenarios":"Passing a raw OKX timeframe string not in the mapping (e.g. lowercase \"1d\", \"6H\", \"12H\", or an unexpected new interval OKX introduces) into okx_timeframe_as_bar_spec, or building a BarType from a user/config-supplied timeframe string.","commonSituations":"Storing timeframes in config files with mixed case or venue-agnostic strings like \"1day\"; OKX adding new candle intervals that the adapter table has not been updated for; hand-constructing requests from OKX API docs strings.","solutions":["Print/log the offending timeframe string and normalize it to the exact OKX spelling (\"1m\",\"3m\",\"5m\",\"15m\",\"30m\",\"1H\",\"2H\",\"4H\",\"1D\",...) before calling","Check whether OKX introduced a new interval and add a mapping arm plus a BAR_SPEC constant in the adapter","Canonicalize config values to the adapter's expected casing (capital H/D/W/M/Y, lowercase m)"],"exampleFix":"// before\nlet tf = \"1d\"; // user config\nlet bar_spec = okx_timeframe_as_bar_spec(tf)?; // bails\n// after\nlet tf = \"1D\"; // normalized OKX timeframe\nlet bar_spec = okx_timeframe_as_bar_spec(tf)?;","handlingStrategy":"validation","validationCode":"fn normalize_tf(tf: &str) -> String {\n    let t = tf.trim().to_uppercase().replace(\"MIN\", \"m\");\n    if t.ends_with('M') && t[..t.len()-1].chars().all(|c| c.is_ascii_digit()) && tf.ends_with(\"min\") { format!(\"{}m\", &t[..t.len()-1]) } else { t }\n}\n// validate membership before calling\nconst VALID: [&str; 15] = [\"1m\",\"3m\",\"5m\",\"15m\",\"30m\",\"1H\",\"2H\",\"4H\",\"1D\",\"2D\",\"3D\",\"5D\",\"1W\",\"1M\",\"3M\"];","typeGuard":null,"tryCatchPattern":"match okx_timeframe_as_bar_spec(tf) {\n    Ok(spec) => build_bar_type(spec),\n    Err(e) => log::error!(\"bad OKX timeframe '{tf}': {e}\"),\n}","preventionTips":["Store timeframes in config exactly as OKX spells them (case-sensitive)","Normalize user input casing before mapping","Update the mapping table when OKX adds new intervals"],"tags":["rust","okx","adapter","bars","parsing"],"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-14T05:17:10.506Z"}