nautechsystems/nautilus_trader · error
Invalid `BarSpecification` for timeframe, was {bar_spec}
Error message
Invalid `BarSpecification` for timeframe, was {bar_spec} What it means
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.
Source
Thrown at crates/adapters/okx/src/common/parse.rs:1470
BAR_SPEC_3_MINUTE_LAST => "3m",
BAR_SPEC_5_MINUTE_LAST => "5m",
BAR_SPEC_15_MINUTE_LAST => "15m",
BAR_SPEC_30_MINUTE_LAST => "30m",
BAR_SPEC_1_HOUR_LAST => "1H",
BAR_SPEC_2_HOUR_LAST => "2H",
BAR_SPEC_4_HOUR_LAST => "4H",
BAR_SPEC_6_HOUR_LAST => "6H",
BAR_SPEC_12_HOUR_LAST => "12H",
BAR_SPEC_1_DAY_LAST => "1D",
BAR_SPEC_2_DAY_LAST => "2D",
BAR_SPEC_3_DAY_LAST => "3D",
BAR_SPEC_5_DAY_LAST => "5D",
BAR_SPEC_1_WEEK_LAST => "1W",
BAR_SPEC_1_MONTH_LAST => "1M",
BAR_SPEC_3_MONTH_LAST => "3M",
BAR_SPEC_6_MONTH_LAST => "6M",
BAR_SPEC_12_MONTH_LAST => "1Y",
_ => anyhow::bail!("Invalid `BarSpecification` for timeframe, was {bar_spec}"),
};
Ok(timeframe)
}
/// Converts OKX timeframe string to Nautilus bar specification.
///
/// # Errors
///
/// Returns an error if the timeframe string is not recognized.
pub fn okx_timeframe_as_bar_spec(timeframe: &str) -> anyhow::Result<BarSpecification> {
let bar_spec = match timeframe {
"1s" => BAR_SPEC_1_SECOND_LAST,
"1m" => BAR_SPEC_1_MINUTE_LAST,
"3m" => BAR_SPEC_3_MINUTE_LAST,
"5m" => BAR_SPEC_5_MINUTE_LAST,
"15m" => BAR_SPEC_15_MINUTE_LAST,
"30m" => BAR_SPEC_30_MINUTE_LAST,
"1H" => BAR_SPEC_1_HOUR_LAST,View on GitHub (pinned to 18893faf8b)
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
Example fix
// before let spec = BarSpecification::new(1, BarAggregation::Minute, PriceType::Bid); let tf = bar_spec_as_okx_timeframe(&spec)?; // bails // after let spec = BAR_SPEC_1_MINUTE_LAST; let tf = bar_spec_as_okx_timeframe(&spec)?; // "1m"
Defensive patterns
Strategy: validation
Validate before calling
if bar_type.spec().aggregation != BarAggregation::Minute
|| bar_type.spec().price_type != PriceType::Last {
return Err("OKX requires LAST-price time bars".into());
} Try / catch
match bar_spec_as_okx_timeframe(&spec) {
Ok(tf) => request_bars(tf),
Err(e) => log::error!("unsupported bar spec for OKX REST: {e}"),
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid `BarSpecification` for channel, was {bar_spec}
- Invalid `BarSpecification` for mark price channel, was {bar_
- Invalid timeframe for `BarSpecification`, was {timeframe}
- Unsupported bar specification for AX: {step}-{:?}
- Unknown position currency '{pos_ccy}' for instrument {instru
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/c8e50265bf9af5e4.
Report an issue: GitHub.