nautechsystems/nautilus_trader · error · anyhow::Error

dYdX only supports EXTERNAL aggregation, was {:?}

Error message

dYdX only supports EXTERNAL aggregation, was {:?}

What it means

dYdX provides raw candle data via its Indexer HTTP API, so the adapter can only build bars with EXTERNAL aggregation source. `bar_type_to_resolution` (used by `request_bars`) rejects any BarType whose aggregation source is INTERNAL since the adapter cannot supply internal-aggregated bars.

Source

Thrown at crates/adapters/dydx/src/http/client.rs:116

        enums::{DydxCandleResolution, DydxNetwork},
        instrument_cache::InstrumentCache,
        parse::extract_raw_symbol,
    },
    http::parse::{parse_account_state_from_http, parse_instrument_any},
};

/// Maximum number of candles returned per dYdX API request.
const DYDX_MAX_BARS_PER_REQUEST: u32 = 1_000;

/// Perpetual markets endpoint (shared between `get_markets` and `get_market`).
const ENDPOINT_PERPETUAL_MARKETS: &str = "/v4/perpetualMarkets";

const QUERY_MARKET_TYPE_PERPETUAL: &str = "marketType=PERPETUAL";
const DYDX_INDEXER_REPORT_LIMIT: u32 = 1_000;

fn bar_type_to_resolution(bar_type: &BarType) -> anyhow::Result<DydxCandleResolution> {
    if bar_type.aggregation_source() != AggregationSource::External {
        anyhow::bail!(
            "dYdX only supports EXTERNAL aggregation, was {:?}",
            bar_type.aggregation_source()
        );
    }

    let spec = bar_type.spec();
    if spec.price_type != PriceType::Last {
        anyhow::bail!(
            "dYdX only supports LAST price type, was {:?}",
            spec.price_type
        );
    }

    DydxCandleResolution::from_bar_spec(&spec)
}

/// Default dYdX Indexer REST API rate limit.
///

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Construct the BarType with `AggregationSource::External`
  2. If internal aggregation is desired, request EXTERNAL bars from dYdX and let the data engine aggregate separately

Example fix

// before
let bar_type = BarType::new(instrument_id, spec, AggregationSource::Internal);
// after
let bar_type = BarType::new(instrument_id, spec, AggregationSource::External);
Defensive patterns

Strategy: validation

Validate before calling

assert_eq!(bar_type.aggregation_source(), AggregationSource::External, "dYdX requires EXTERNAL aggregation");

Prevention

When it happens

Trigger: Calling `request_bars` with a BarType constructed with `AggregationSource::Internal`, e.g. `BarType::new(instrument_id, BarSpecification::new(1, BarAggregation::Minute, PriceType::Last), AggregationSource::Internal)`.

Common situations: Copying bar request code from adapters that support internal aggregation; a data engine configured to aggregate internally rather than requesting external bars from the venue.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/fd39c2d5f04e6cf1. Report an issue: GitHub.