nautechsystems/nautilus_trader · error

funding_interval_hour out of bounds

Error message

funding_interval_hour out of bounds

What it means

When converting a Bybit linear ticker's `funding_interval_hour` into minutes, the adapter multiplies hours by 60 with overflow checking. If the multiplication overflows u16 (hours > 1092), the value is out of bounds and this error is thrown.

Source

Thrown at crates/adapters/bybit/src/websocket/parse.rs:487

        );
    }

    let funding_rate = funding_rate_str
        .as_str()
        .parse::<Decimal>()
        .with_context(|| {
            format!("invalid funding_rate value '{funding_rate_str}' for {instrument_id}")
        })?;

    let funding_interval = if let Some(funding_interval_hour) = &data.funding_interval_hour {
        let funding_interval_hour = funding_interval_hour
            .as_str()
            .parse::<u16>()
            .context("invalid funding_interval_hour value")?;
        Some(
            funding_interval_hour
                .checked_mul(60)
                .ok_or_else(|| anyhow::anyhow!("funding_interval_hour out of bounds"))?,
        )
    } else {
        None
    };

    let next_funding_ns = if let Some(next_funding_time) = &data.next_funding_time {
        let next_funding_millis = next_funding_time
            .as_str()
            .parse::<i64>()
            .context("invalid next_funding_time value")?;
        Some(parse_millis_i64(next_funding_millis, "next_funding_time")?)
    } else {
        None
    };

    Ok(FundingRateUpdate::new(
        instrument_id,
        funding_rate,

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Log the raw funding_interval_hour value and confirm its unit with the current Bybit API docs
  2. Change the parse target to u32/u64 if Bybit widened the field (update the adapter)
  3. Filter or reject tickers with implausible funding intervals before conversion

Example fix

// before: u16 overflows on large values
let funding_interval_hour = data.funding_interval_hour.as_str().parse::<u16>()?;
// after: widen the type
let funding_interval_hour = data.funding_interval_hour.as_str().parse::<u32>()?;
Defensive patterns

Strategy: validation

Validate before calling

if interval_hour is not None and not (0 < interval_hour < 1093):
    raise ValueError(f'implausible funding_interval_hour: {interval_hour}')

Try / catch

match parse_ticker_linear_funding(...) { Err(e) if e.to_string().contains("out of bounds") => { log_payload(raw); skip }, other => other }

Prevention

When it happens

Trigger: Receiving a ticker/funding update on a linear instrument where `funding_interval_hour` parses to a u16 value whose *60 exceeds u16 range (>= 1093 hours).

Common situations: Upstream schema change or corrupted payload reporting hours in a different unit (e.g. minutes or seconds); fixture data with unrealistic funding intervals.

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/53693ecdcfdc9963. Report an issue: GitHub.