nautechsystems/nautilus_trader · error
Invalid `BarSpecification` for channel, was {bar_spec}
Error message
Invalid `BarSpecification` for channel, was {bar_spec} What it means
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.
Source
Thrown at crates/adapters/okx/src/common/parse.rs:1404
BAR_SPEC_3_MINUTE_LAST => OKXWsChannel::Candle3Minute,
BAR_SPEC_5_MINUTE_LAST => OKXWsChannel::Candle5Minute,
BAR_SPEC_15_MINUTE_LAST => OKXWsChannel::Candle15Minute,
BAR_SPEC_30_MINUTE_LAST => OKXWsChannel::Candle30Minute,
BAR_SPEC_1_HOUR_LAST => OKXWsChannel::Candle1Hour,
BAR_SPEC_2_HOUR_LAST => OKXWsChannel::Candle2Hour,
BAR_SPEC_4_HOUR_LAST => OKXWsChannel::Candle4Hour,
BAR_SPEC_6_HOUR_LAST => OKXWsChannel::Candle6Hour,
BAR_SPEC_12_HOUR_LAST => OKXWsChannel::Candle12Hour,
BAR_SPEC_1_DAY_LAST => OKXWsChannel::Candle1Day,
BAR_SPEC_2_DAY_LAST => OKXWsChannel::Candle2Day,
BAR_SPEC_3_DAY_LAST => OKXWsChannel::Candle3Day,
BAR_SPEC_5_DAY_LAST => OKXWsChannel::Candle5Day,
BAR_SPEC_1_WEEK_LAST => OKXWsChannel::Candle1Week,
BAR_SPEC_1_MONTH_LAST => OKXWsChannel::Candle1Month,
BAR_SPEC_3_MONTH_LAST => OKXWsChannel::Candle3Month,
BAR_SPEC_6_MONTH_LAST => OKXWsChannel::Candle6Month,
BAR_SPEC_12_MONTH_LAST => OKXWsChannel::Candle1Year,
_ => anyhow::bail!("Invalid `BarSpecification` for channel, was {bar_spec}"),
};
Ok(channel)
}
/// Converts Nautilus bar specification to OKX mark price channel.
///
/// # Errors
///
/// Returns an error if the bar specification does not map to a mark price
/// channel.
pub fn bar_spec_as_okx_mark_price_channel(
bar_spec: BarSpecification,
) -> anyhow::Result<OKXWsChannel> {
let channel = match bar_spec {
BAR_SPEC_1_SECOND_LAST => OKXWsChannel::MarkPriceCandle1Second,
BAR_SPEC_1_MINUTE_LAST => OKXWsChannel::MarkPriceCandle1Minute,
BAR_SPEC_3_MINUTE_LAST => OKXWsChannel::MarkPriceCandle3Minute,
BAR_SPEC_5_MINUTE_LAST => OKXWsChannel::MarkPriceCandle5Minute,View on GitHub (pinned to 18893faf8b)
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
Example fix
// before let bar_type = BarType::from_spec(instrument_id, BarSpecification::new(2, BarAggregation::Day, PriceType::Last)); data.subscribe_bars(bar_type); // bails: no Candle2Day price channel // after let bar_type = BarType::from_spec(instrument_id, BAR_SPEC_1_DAY_LAST); data.subscribe_bars(bar_type);
Defensive patterns
Strategy: validation
Validate before calling
// only subscribe with supported OKX bar specs
const SUPPORTED: &[BarSpecification] = &[
BAR_SPEC_1_MINUTE_LAST, BAR_SPEC_1_HOUR_LAST, BAR_SPEC_1_DAY_LAST, BAR_SPEC_1_WEEK_LAST,
];
assert!(SUPPORTED.contains(&bar_type.spec())); Try / catch
match bar_spec_as_okx_channel(bar_type.spec()) {
Ok(channel) => subscribe(channel),
Err(e) => log::error!("bar spec not supported by OKX: {e}"),
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Invalid `BarSpecification` for mark price channel, was {bar_
- Invalid `BarSpecification` for timeframe, was {bar_spec}
- Invalid timeframe for `BarSpecification`, was {timeframe}
- Unsupported bar specification for AX: {step}-{:?}
- std::mem::take(&mut self.shutdown_errors).join("; ")
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/eae8e155b6650455.
Report an issue: GitHub.