nautechsystems/nautilus_trader · error

invalid depth {depth}; supported depths: {DERIBIT_BOOK_VALID

Error message

invalid depth {depth}; supported depths: {DERIBIT_BOOK_VALID_DEPTHS:?}

What it means

Deribit only publishes book snapshots at a fixed set of depths. subscribe_book_deltas reads the optional "depth" param (defaulting to DERIBIT_BOOK_DEFAULT_DEPTH) and rejects values not in DERIBIT_BOOK_VALID_DEPTHS.

Source

Thrown at crates/adapters/deribit/src/data.rs:918

            .ok_or_else(|| anyhow::anyhow!("WebSocket client not initialized"))?
            .clone();
        let http_client = self.http_client.clone();
        let instruments = Arc::clone(&self.instruments);
        let interval = self.get_interval(&cmd.params);

        let depth = cmd
            .depth
            .map(|d| d.get() as u32)
            .or_else(|| {
                cmd.params
                    .as_ref()
                    .and_then(|p| p.get_u64("depth"))
                    .map(|n| n as u32)
            })
            .unwrap_or(DERIBIT_BOOK_DEFAULT_DEPTH);

        if !DERIBIT_BOOK_VALID_DEPTHS.contains(&depth) {
            anyhow::bail!("invalid depth {depth}; supported depths: {DERIBIT_BOOK_VALID_DEPTHS:?}");
        }

        let group = cmd
            .params
            .as_ref()
            .and_then(|p| p.get_str("group"))
            .unwrap_or(DERIBIT_BOOK_DEFAULT_GROUP)
            .to_string();

        log::debug!(
            "Subscribing to book deltas for {} (group: {}, depth: {}, interval: {}, book_type: {:?})",
            instrument_id,
            group,
            depth,
            interval.map_or("100ms (default)".to_string(), |i| i.to_string()),
            cmd.book_type
        );

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Change the "depth" param to one of the values in DERIBIT_BOOK_VALID_DEPTHS
  2. Omit the depth param entirely to use DERIBIT_BOOK_DEFAULT_DEPTH
  3. Clamp/snap requested depth to the nearest supported depth before subscribing

Example fix

// before
let params = indexmap! { "depth" => 5u64 };
// after
let params = indexmap! { "depth" => 10u64 }; // one of DERIBIT_BOOK_VALID_DEPTHS
Defensive patterns

Strategy: validation

Validate before calling

const VALID: &[u32] = &DERIBIT_BOOK_VALID_DEPTHS;
if !VALID.contains(&depth) {
    return Err(anyhow::anyhow!("depth {depth} not in {VALID:?}"));
}

Try / catch

if let Err(e) = client.subscribe_book_deltas(cmd).await {
    if e.to_string().contains("invalid depth") { cmd.params.insert("depth".into(), DERIBIT_BOOK_DEFAULT_DEPTH.into()); retry(); }
}

Prevention

When it happens

Trigger: Calling subscribe_book_deltas with params.depth set to a u64 not contained in DERIBIT_BOOK_VALID_DEPTHS (e.g. depth=5 or depth=2000 when valid depths are like 1, 10, 20, 50, 100, 200, 1000).

Common situations: Porting depth values from another exchange adapter; hand-typing a depth that seems reasonable; programmatic depth selection that doesn't snap to the venue's allowed list.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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