nautechsystems/nautilus_trader · error · anyhow::Error

recv_window_ms must be in the inclusive range 1..=60000, was

Error message

recv_window_ms must be in the inclusive range 1..=60000, was {recv_window_ms}

What it means

recv_window_ms defines the signed-request receive window sent to Binance and must be between 1 and 60000 milliseconds inclusive, matching Binance API limits. validate_recv_window() throws this error for 0 or values above 60 seconds.

Solutions

  1. Set recv_window_ms within 1..=60000, e.g. 5000 (5 seconds).
  2. Check the source value's unit: if configured in seconds, multiply by 1000 before assigning.
  3. Fix env-var/config loading so an unset value does not produce 0.

Example fix

// before
let config = BinanceClientConfig { recv_window_ms: 120_000, .. }; // 2 minutes, too large
// after
let config = BinanceClientConfig { recv_window_ms: 5_000, .. }; // 5 seconds
Defensive patterns

Strategy: validation

Validate before calling

fn recv_window_ok(recv_window_ms: u64) -> bool {
    (1..=60_000).contains(&recv_window_ms)
}

Prevention

When it happens

Trigger: Setting recv_window_ms to 0, or to a value > 60000 (e.g. 120000), then calling validate() on the Binance config.

Common situations: Confusing milliseconds with seconds (setting 60000 thinking it's 60000s, or setting 5 thinking it's 5s -> out of range intent); env var defaulting to 0 when unset; copying a recv_window value from a different exchange configured in seconds.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

Thrown at crates/adapters/binance/src/config.rs:452

        self.instrument_provider.validate(self.product_type)?;

        if self.us {
            anyhow::ensure!(
                self.product_type == BinanceProductType::Spot,
                "Binance US supports Spot clients only"
            );
            anyhow::ensure!(
                self.environment == BinanceEnvironment::Live,
                "Binance US supports the Live environment only"
            );
        }

        Ok(())
    }
}

fn validate_recv_window(recv_window_ms: u64) -> anyhow::Result<()> {
    anyhow::ensure!(
        (1..=60_000).contains(&recv_window_ms),
        "recv_window_ms must be in the inclusive range 1..=60000, was {recv_window_ms}"
    );
    Ok(())
}

impl ClientConfig for BinanceExecutionClientConfig {
    fn as_any(&self) -> &dyn Any {
        self
    }
}

#[cfg(test)]
mod tests {
    use rstest::rstest;

    use super::*;

View on GitHub (pinned to 18893faf8b)