nautechsystems/nautilus_trader · error · anyhow::Error

dYdX only supports LAST price type, was {:?}

Error message

dYdX only supports LAST price type, was {:?}

What it means

bar_type_to_resolution received a bar type whose price type (from PriceType on the bar spec) is not LAST; the dYdX v4 indexer only serves candles computed from last-trade prices, so any other price source cannot be requested.

Source

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

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.
///
/// The dYdX Indexer API rate limit is 100 requests per 10 seconds per IP.
/// We use 9 req/s (vs the exact 10) to avoid edge-case 429s from
/// GCRA vs server sliding-window misalignment at the boundary.
pub static DYDX_REST_QUOTA: LazyLock<Quota> = LazyLock::new(|| {
    Quota::per_second(NonZeroU32::new(9).expect("non-zero")).expect("valid constant")
});

type DydxRestRateLimiter = Arc<RateLimiter<Ustr, MonotonicClock>>;

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Change the bar spec price type to `PriceType::Last`
  2. If bid/ask bars are required, source them from a different adapter or compute them client-side from trade data

Example fix

// before
let spec = BarSpecification::new(1, BarAggregation::Minute, PriceType::Mid);
// after
let spec = BarSpecification::new(1, BarAggregation::Minute, PriceType::Last);
Defensive patterns

Strategy: validation

Validate before calling

assert_eq!(bar_type.spec().price_type, PriceType::Last, "dYdX requires LAST price type");

Prevention

When it happens

Trigger: Calling `request_bars` with a bar spec using `PriceType::Bid`, `PriceType::Ask`, `PriceType::Mid`, or `PriceType::Vwap` instead of `PriceType::Last`.

Common situations: Requesting bid/ask candles as one would from a broker with quote data; building bar specs generically from user config without restricting price type for dYdX.

Related errors


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