nautechsystems/nautilus_trader · error
Price overflow: {price_raw} exceeds PriceRaw range
Error message
Price overflow: {price_raw} exceeds PriceRaw range What it means
price_from_u256 casts the validated raw price into an i128 (PriceRaw) before constructing the Price. This error is a defensive fallback thrown if the U256 value cannot fit into i128 despite passing the PRICE_RAW_MAX check — an internal invariant guard protecting Price::from_raw_checked from out-of-range input.
Source
Thrown at crates/model/src/defi/tick_map/sqrt_price_math.rs:450
divisor_base,
&[fixed_scalar, decimal_adjustment],
)?
} else {
FullMath::mul_div_scaled(sqrt_price, sqrt_price, divisor_base, &[fixed_scalar])?
/ decimal_adjustment
};
price_from_u256(price_raw)
}
pub(crate) fn price_from_u256(price_raw: U256) -> anyhow::Result<Price> {
anyhow::ensure!(
price_raw <= U256::from(PRICE_RAW_MAX as u128),
"Price overflow: {price_raw} exceeds maximum valid raw price {PRICE_RAW_MAX}"
);
let price_raw: i128 = price_raw
.try_into()
.map_err(|_| anyhow::anyhow!("Price overflow: {price_raw} exceeds PriceRaw range"))?;
Price::from_raw_checked(price_raw, FIXED_PRECISION).map_err(Into::into)
}
#[cfg(test)]
mod tests {
// Most of the tests are based on https://github.com/Uniswap/v3-core/blob/main/test/SqrtPriceMath.spec.ts
use rstest::*;
use super::*;
use crate::defi::tick_map::{
full_math::{DECIMAL_EXPONENT_MAX, Q96_U160},
tick_math::MAX_SQRT_RATIO,
};
#[rstest]
#[should_panic(expected = "sqrt_price_x96 must be greater than zero")]
fn test_if_get_next_sqrt_price_from_input_panic_if_price_zero() {View on GitHub (pinned to 18893faf8b)
Solutions
- Do not attempt to work around it; if hit, file an issue — it indicates an internal constant inconsistency.
- Verify your nautilus_model version constants (PRICE_RAW_MAX vs PriceRaw/i128 range) are consistent.
- Update to the latest release where the invariant holds.
Defensive patterns
Strategy: try-catch
Try / catch
// Practically unreachable; treat as a bug report if seen
let price = price_from_u256(raw).map_err(|e| {
if e.to_string().contains("PriceRaw range") {
anyhow::anyhow!("internal error: PRICE_RAW_MAX inconsistent with PriceRaw: {e}")
} else { e }
}); Prevention
- Keep PRICE_RAW_MAX and the PriceRaw (i128) type in sync when upgrading
- Do not modify library constants; report inconsistencies upstream
When it happens
Trigger: Practically unreachable via the public API because the preceding PRICE_RAW_MAX ensure() rejects values above PRICE_RAW_MAX first; it can only fire if PRICE_RAW_MAX itself exceeds i128 range or the check and cast diverge (version change in constants).
Common situations: Custom forks or modified builds where PRICE_RAW_MAX was changed; unexpected library version changes altering constant definitions.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- fill group is empty
- Close command should not be drained
- Flush command should not be drained
- Order invariant violated: first event must be OrderInitializ
- noid '{}' does not match new order oid '{}'
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/516535fe965e0c5d.
Report an issue: GitHub.