nautechsystems/nautilus_trader · error · anyhow::Error

invalid Binance Futures order-book depth

Error message

invalid Binance Futures order-book depth {depth}; valid values are {BINANCE_BOOK_DEPTHS:?}

What it means

Binance Futures depth endpoints only accept specific depth values (the BINANCE_BOOK_DEPTHS set, e.g. 5, 10, 20, 50, 100, 500, 1000), so request_book_snapshot validates the requested depth against that set. The depth defaults to 1000 when not specified.

Solutions

  1. Set the request depth to one of the values listed in the error message (from BINANCE_BOOK_DEPTHS)
  2. Omit depth so the default of 1000 is used
  3. Clamp/snap the configured depth to the nearest supported value before requesting

Example fix

// before
let depth = NonZeroUsize::new(150).unwrap();
request_book_snapshot(RequestBookSnapshot { depth: Some(depth), .. });
// after
let depth = NonZeroUsize::new(100).unwrap(); // nearest supported value in BINANCE_BOOK_DEPTHS
request_book_snapshot(RequestBookSnapshot { depth: Some(depth), .. });
Defensive patterns

Strategy: validation

Validate before calling

let depth = depth.unwrap_or(1000);
assert!(BINANCE_BOOK_DEPTHS.contains(&(depth as u32)), "depth {depth} unsupported");

Prevention

When it happens

Trigger: Calling request_book_snapshot (order-book snapshot request via the Binance Futures data client) with request.depth set to a value not in BINANCE_BOOK_DEPTHS, e.g. 25, 200, or 1500.

Common situations: Configuring a generic depth value like 20 works on one venue but fails on Binance Futures if 20 is not in the supported set; or copying depth settings from the spot adapter, which supports different depth tiers.

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/3dd5d8976dda2259. Report an issue: GitHub.

Appendix: source

Thrown at crates/adapters/binance/src/futures/data.rs:3090

                        end_nanos,
                        clock.get_time_ns(),
                        params,
                    ));

                    if let Err(e) = sender.send(DataEvent::Response(response)) {
                        log::error!("Failed to send bars response: {e}");
                    }
                }
                Err(e) => log::error!("Bar request failed: {e:?}"),
            }
        });

        Ok(())
    }

    fn request_book_snapshot(&self, request: RequestBookSnapshot) -> anyhow::Result<()> {
        let depth = request.depth.map_or(1000, |value| value.get() as u32);
        anyhow::ensure!(
            BINANCE_BOOK_DEPTHS.contains(&depth),
            "invalid Binance Futures order-book depth {depth}; valid values are {BINANCE_BOOK_DEPTHS:?}"
        );
        let http = self.http_client.clone();
        let sender = self.data_sender.clone();
        let instrument_id = request.instrument_id;
        let request_id = request.request_id;
        let client_id = request.client_id.unwrap_or(self.client_id);
        let params = request.params;
        let clock = self.clock;

        self.spawn_command(async move {
            match http.request_book_snapshot(instrument_id, Some(depth)).await {
                Ok(book) => {
                    let response = DataResponse::Book(BookResponse::new(
                        request_id,
                        client_id,
                        instrument_id,

View on GitHub (pinned to 18893faf8b)