nautechsystems/nautilus_trader · error
Invalid `BarSpecification` for mark price channel, was {bar_
Error message
Invalid `BarSpecification` for mark price channel, was {bar_spec} What it means
bar_spec_as_okx_mark_price_channel maps a Nautilus BarSpecification to an OKX mark-price candle websocket channel. The mark-price candle table is smaller than the regular candle table (it stops at 3M and has no 6M/1Y entries), so unsupported specs — including 6M/12M that work for regular candles — bail with this message.
Source
Thrown at crates/adapters/okx/src/common/parse.rs:1437
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,
BAR_SPEC_15_MINUTE_LAST => OKXWsChannel::MarkPriceCandle15Minute,
BAR_SPEC_30_MINUTE_LAST => OKXWsChannel::MarkPriceCandle30Minute,
BAR_SPEC_1_HOUR_LAST => OKXWsChannel::MarkPriceCandle1Hour,
BAR_SPEC_2_HOUR_LAST => OKXWsChannel::MarkPriceCandle2Hour,
BAR_SPEC_4_HOUR_LAST => OKXWsChannel::MarkPriceCandle4Hour,
BAR_SPEC_6_HOUR_LAST => OKXWsChannel::MarkPriceCandle6Hour,
BAR_SPEC_12_HOUR_LAST => OKXWsChannel::MarkPriceCandle12Hour,
BAR_SPEC_1_DAY_LAST => OKXWsChannel::MarkPriceCandle1Day,
BAR_SPEC_2_DAY_LAST => OKXWsChannel::MarkPriceCandle2Day,
BAR_SPEC_3_DAY_LAST => OKXWsChannel::MarkPriceCandle3Day,
BAR_SPEC_5_DAY_LAST => OKXWsChannel::MarkPriceCandle5Day,
BAR_SPEC_1_WEEK_LAST => OKXWsChannel::MarkPriceCandle1Week,
BAR_SPEC_1_MONTH_LAST => OKXWsChannel::MarkPriceCandle1Month,
BAR_SPEC_3_MONTH_LAST => OKXWsChannel::MarkPriceCandle3Month,
_ => anyhow::bail!("Invalid `BarSpecification` for mark price channel, was {bar_spec}"),
};
Ok(channel)
}
/// Converts Nautilus bar specification to OKX timeframe string.
///
/// # Errors
///
/// Returns an error if the bar specification does not have a corresponding
/// OKX timeframe value.
pub fn bar_spec_as_okx_timeframe(bar_spec: BarSpecification) -> anyhow::Result<&'static str> {
let timeframe = match bar_spec {
BAR_SPEC_1_SECOND_LAST => "1s",
BAR_SPEC_1_MINUTE_LAST => "1m",
BAR_SPEC_3_MINUTE_LAST => "3m",
BAR_SPEC_5_MINUTE_LAST => "5m",
BAR_SPEC_15_MINUTE_LAST => "15m",
BAR_SPEC_30_MINUTE_LAST => "30m",View on GitHub (pinned to 18893faf8b)
Solutions
- Verify the bar spec against bar_spec_as_okx_mark_price_channel's supported list (1m..1D, 2D/3D/5D/1W/1M/3M, LAST)
- Use a supported mark-price interval such as BAR_SPEC_1_HOUR_LAST instead of 6M/12M
- If only regular candles were intended, use the standard candle channel rather than the mark-price one
Defensive patterns
Strategy: validation
Validate before calling
let channel = bar_spec_as_okx_mark_price_channel(bar_type.spec())
.or_else(|_| bar_spec_as_okx_channel(bar_type.spec()));
if channel.is_err() {
eprintln!("spec {} unsupported for mark-price candles", bar_type.spec());
} Try / catch
match bar_spec_as_okx_mark_price_channel(&spec) {
Ok(ch) => subscribe(ch),
Err(e) => log::warn!("falling back to regular candles: {e}"),
} Prevention
- Remember mark-price candles support fewer intervals (no 6M/12M) than regular candles
- Keep separate config entries for regular vs mark-price bar specs
- Use LAST price type for all candle subscriptions
When it happens
Trigger: Subscribing to OKX mark-price bars with a BarSpecification not in the table: 6M or 12M intervals (supported for regular candles but not mark-price), non-LAST price types, or non-time aggregations such as tick/volume bars.
Common situations: Reusing the same bar spec for both regular and mark-price candle subscriptions and assuming identical support; upgrading OKX interval support and trying newer intervals for mark-price candles; typo'd aggregation config.
Related errors
- Invalid `BarSpecification` for channel, was {bar_spec}
- Invalid `BarSpecification` for timeframe, was {bar_spec}
- 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/0a9e03c5213e935d.
Report an issue: GitHub.