nautechsystems/nautilus_trader · error
`durations_seconds` request parameter must contain values of
Error message
`durations_seconds` request parameter must contain values of at least one nanosecond, was {value} What it means
After converting seconds to nanoseconds, parse_time_range_duration requires the result to be at least 1 ns; smaller values (e.g. 0 or 1e-10 seconds) cannot be represented as a positive DurationNanos and are rejected. null entries remain allowed.
Source
Thrown at crates/data/src/engine/time_range.rs:767
fn parse_time_range_duration(value: &Value) -> anyhow::Result<Option<DurationNanos>> {
if value.is_null() {
return Ok(None);
}
let seconds = value.as_f64().with_context(|| {
format!("`durations_seconds` request parameter must contain numbers or null, was {value}")
})?;
if !seconds.is_finite() || seconds < 0.0 {
anyhow::bail!(
"`durations_seconds` request parameter must contain non-negative finite values, was {value}"
);
}
let nanos = seconds * NANOSECONDS_IN_SECOND as f64;
if nanos < 1.0 {
anyhow::bail!(
"`durations_seconds` request parameter must contain values of at least one nanosecond, was {value}"
);
}
if nanos > u64::MAX as f64 {
anyhow::bail!("`durations_seconds` value is too large, was {value}");
}
Ok(Some(DurationNanos::new(nanos as u64)))
}
#[cfg(test)]
mod tests {
use nautilus_common::messages::data::{RequestCommand, RequestInstrument};
use nautilus_core::{Params, UUID4, UnixNanos};
use nautilus_model::identifiers::{ClientId, InstrumentId};
use rstest::rstest;
use serde_json::json;View on GitHub (pinned to 18893faf8b)
Solutions
- Use durations >= 1 nanosecond (1e-9 seconds)
- Replace zero-duration entries with null to indicate 'no duration'
- Round sub-nanosecond durations up to at least 1ns if a duration is truly required
Example fix
// before json!(["durations_seconds" => [0.0000000001]]) // after json!(["durations_seconds" => [0.000000001]]) // 1 ns, or null for 'none'
Defensive patterns
Strategy: validation
Validate before calling
fn at_least_one_ns(v: &serde_json::Value) -> bool {
matches!(v.as_f64(), Some(s) if s * 1e9 >= 1.0)
} Type guard
let ok = values.iter().all(|v| v.is_null() || at_least_one_ns(v));
Prevention
- Use null, not 0, for 'no duration' entries
- Remember the engine's resolution is nanoseconds; round up sub-ns durations
When it happens
Trigger: Passing durations_seconds entries of 0 or sub-nanosecond values like 0.0000000001 (1e-10 s), so nanos < 1.0.
Common situations: Using 0 as a 'no duration' sentinel instead of null; fractional-second values below the nanosecond resolution of the engine; floating-point underflow from tiny computed durations.
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
- `durations_seconds` request parameter must contain non-negat
- `durations_seconds` value is too large, was {value}
- {field} exceeds the maximum backoff duration
- {e}
- DurationNanos overflow in from_micros
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/567ca7de82b69c64.
Report an issue: GitHub.