nautechsystems/nautilus_trader · error
OKX does not support {a:?} aggregation
Error message
OKX does not support {a:?} aggregation What it means
When building OKX bar (candle) requests, the adapter maps Nautilus BarAggregation variants to OKX bar-size strings. Only Second, Minute, Hour, Day, Week, and Month aggregations are supported; any other aggregation (e.g. Tick, Volume) hits a catch-all arm and bails. OKX simply has no candle granularity corresponding to those aggregations.
Source
Thrown at crates/adapters/okx/src/http/client.rs:3576
return Ok(Vec::new());
}
if let Some(e) = end
&& e > now
{
end = Some(now);
}
let spec = bar_type.spec();
let step = spec.step.get();
let bar_param = match spec.aggregation {
BarAggregation::Second => format!("{step}s"),
BarAggregation::Minute => format!("{step}m"),
BarAggregation::Hour => format!("{step}H"),
BarAggregation::Day => format!("{step}D"),
BarAggregation::Week => format!("{step}W"),
BarAggregation::Month => format!("{step}M"),
a => anyhow::bail!("OKX does not support {a:?} aggregation"),
};
let slot_ms: i64 = match spec.aggregation {
BarAggregation::Second => (step as i64) * 1_000,
BarAggregation::Minute => (step as i64) * 60_000,
BarAggregation::Hour => (step as i64) * 3_600_000,
BarAggregation::Day => (step as i64) * 86_400_000,
BarAggregation::Week => (step as i64) * 7 * 86_400_000,
BarAggregation::Month => (step as i64) * 30 * 86_400_000,
_ => unreachable!("Unsupported aggregation should have been caught above"),
};
let slot_ns: i64 = slot_ms * 1_000_000;
let mode = match (start, end) {
(None, None) => Mode::Latest,
(Some(_), None) => Mode::Backward, // Changed: when only start is provided, work backward from now
(None, Some(_)) => Mode::Backward,
(Some(_), Some(_)) => Mode::Range,View on GitHub (pinned to 18893faf8b)
Solutions
- Use one of Second/Minute/Hour/Day/Week/Month aggregations in the BarSpec
- Aggregate ticks into time bars locally (via an internal aggregator) instead of asking OKX for tick/volume bars
- Validate the BarSpec aggregation before submitting the request
Example fix
// before let spec = BarSpecification::new(step, BarAggregation::Volume, price_type); // after let spec = BarSpecification::new(step, BarAggregation::Minute, price_type);
Defensive patterns
Strategy: validation
Validate before calling
match spec.aggregation {
BarAggregation::Second | BarAggregation::Minute | BarAggregation::Hour
| BarAggregation::Day | BarAggregation::Week | BarAggregation::Month => {}
other => return Err(anyhow::anyhow!("OKX does not support {other:?} aggregation")),
} Type guard
fn okx_supported_aggregation(a: BarAggregation) -> bool {
matches!(a, BarAggregation::Second | BarAggregation::Minute
| BarAggregation::Hour | BarAggregation::Day
| BarAggregation::Week | BarAggregation::Month)
} Try / catch
if let Err(e) = client.request_bars(bar_type, ...).await {
log::error!("bar request rejected: {e}");
} Prevention
- Restrict OKX BarSpecs to time-based aggregations
- Aggregate ticks or volume bars locally rather than requesting them from OKX
- Validate BarSpec before registering subscriptions
When it happens
Trigger: Requesting OKX historical bars (request_bars / bar subscription) with a BarSpec whose aggregation is Tick, Volume, Value, or another unsupported variant.
Common situations: Configuring a bar aggregator or data request with an aggregation type that works on other venues but not OKX; copy-pasted BarSpec from a crypto data provider that supports volume bars.
Related errors
- Binance Futures does not support {a:?} aggregation
- Deribit does not support {a:?} aggregation
- Unsupported bar aggregation for Kraken Spot: {other:?}
- Only EXTERNAL aggregation is supported
- Aggregation not time based
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/f71d0c7e3e93d24b.
Report an issue: GitHub.