nautechsystems/nautilus_trader · error
Market exit timer interval exceeds the nanosecond range
Error message
Market exit timer interval exceeds the nanosecond range
What it means
When starting a market exit timer, the strategy converts a millisecond interval to a DurationNanos. If the millisecond value overflows the nanosecond range (too large to fit), the conversion fails, the exiting state and attempt counter are reset, and the strategy aborts the timer setup with this error. It guards the clock timer API against invalid durations.
Source
Thrown at crates/trading/src/strategy/mod.rs:1781
Some(time_in_force),
Some(reduce_only),
None,
None,
) {
log::error!("Error closing positions for {instrument_id}: {e}");
}
}
let core = StrategyNative::strategy_core_mut(self);
let interval_ms = core.config.market_exit_interval_ms;
let timer_name = core.market_exit_timer_name;
log::info!("{strategy_id} Setting market exit timer at {interval_ms}ms intervals");
let Ok(interval_ns) = DurationNanos::try_from_millis(interval_ms) else {
core.is_exiting = false;
core.market_exit_attempts = 0;
anyhow::bail!("Market exit timer interval exceeds the nanosecond range");
};
let result = core.clock_mut().set_timer_ns(
timer_name.as_str(),
interval_ns,
None,
None,
None,
None,
None,
);
if let Err(e) = result {
// Reset exit state on timer failure (caller handles pending_stop)
core.is_exiting = false;
core.market_exit_attempts = 0;
return Err(e);
}
View on GitHub (pinned to 18893faf8b)
Solutions
- Check the market exit timer interval configuration value and reduce it to a sane millisecond value
- Add validation/bounds on the interval before it reaches market_exit (e.g. cap at u64::MAX/1_000_000 ns)
- Log and reject the invalid config at startup with a clear message instead of at timer setup
Example fix
// before let interval_ms = config.market_exit_interval_ms; // 10_000_000_000_000_000 // after anyhow::ensure!(config.market_exit_interval_ms <= MAX_INTERVAL_MS, "market exit interval too large"); let interval_ms = config.market_exit_interval_ms;
Defensive patterns
Strategy: validation
Validate before calling
// Rust
const MAX_INTERVAL_MS: u64 = u64::MAX / 1_000_000;
if interval_ms > MAX_INTERVAL_MS {
return Err(anyhow::anyhow!("interval_ms {interval_ms} exceeds nanosecond range"));
} Try / catch
// Rust
match strategy.stop() {
Err(e) if e.to_string().contains("nanosecond range") => {
log::error!("fix market exit interval config: {e}");
}
other => other?,
} Prevention
- Bound-check duration config values at startup, before the strategy runs
- Store intervals in a typed config struct with validated ranges
- Never assemble interval values by string concatenation of user input
When it happens
Trigger: Calling stop (which drives market_exit) with a market exit timer interval in milliseconds that is too large to represent as nanoseconds (e.g. from a misconfigured config value exceeding u64 nanosecond capacity).
Common situations: Config file with an absurd market-exit interval (e.g. seconds entered as nanoseconds, or a typo like 10^18 ms); environment-provided interval parsed without bounds checking.
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
- Invalid config type for AxExecutionClientFactory. Expected A
- Invalid config type for BetfairDataClientFactory. Expected B
- Invalid config type for BetfairExecutionClientFactory. Expec
- Invalid `external_order_claims` type: {e}
- Invalid `external_order_claims` instrument ID {claim}: {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/c9bd29314b20093e.
Report an issue: GitHub.