{"record":{"id":"e33a7101822179b3","repo":"nautechsystems/nautilus_trader","slug":"continuous-future-adjustment-exceeds-priceraw-rang","errorCode":null,"errorMessage":"Continuous-future adjustment exceeds PriceRaw range","messagePattern":"Continuous-future adjustment exceeds PriceRaw range","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/data/src/aggregation.rs","lineNumber":236,"sourceCode":"            return;\n        }\n\n        // Spread mode: scale the Decimal offset to FIXED_PRECISION once so the hot path\n        // can add it straight onto `price.raw`. Signed PriceRaw supports negatives, so\n        // backward-spread offsets that push prices below zero remain representable.\n        self.adjustment_is_ratio = false;\n        let exponent = -(adjustment.scale() as i8);\n        let raw_i128 =\n            mantissa_exponent_to_fixed_i128(adjustment.mantissa(), exponent, FIXED_PRECISION)\n                .expect(\"Failed to scale continuous-future adjustment to fixed precision\");\n\n        #[allow(\n            clippy::useless_conversion,\n            reason = \"i128 to PriceRaw is real when not high-precision\"\n        )]\n        let raw: PriceRaw = raw_i128\n            .try_into()\n            .expect(\"Continuous-future adjustment exceeds PriceRaw range\");\n\n        self.adjustment_raw = raw;\n        self.adjustment_active = self.adjustment_raw != 0;\n    }\n\n    fn apply_adjustment_to_price(&self, price: Price) -> Price {\n        if !self.adjustment_active {\n            return price;\n        }\n\n        if self.adjustment_is_ratio {\n            // Multiply in double; `Price::new` rounds to the target precision.\n            // Float can shift 1 ULP for high-precision raws (spread mode is exact).\n            return Price::new(price.as_f64() * self.adjustment_ratio, price.precision);\n        }\n\n        // Spread: signed raw addition.\n        Price::from_raw(price.raw + self.adjustment_raw, price.precision)","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/data/src/aggregation.rs#L218-L254","documentation":"After successfully scaling the adjustment to i128 fixed units, `set_adjustment` converts it to `PriceRaw` with `try_into().expect(...)`. On non-high-precision builds PriceRaw is i64, so an adjustment magnitude beyond i64 raw units panics.","triggerScenarios":"Calling `set_adjustment` with an adjustment whose fixed-precision i128 value does not fit in PriceRaw (i64), e.g. an adjustment of billions of dollars expressed at 9-decimal fixed precision.","commonSituations":"Spread adjustments computed from mis-scaled feeds (mantissa multiplied by an extra 10^k); corrupted market data with absurd price levels; accidentally passing a cumulative index level instead of a per-step offset.","solutions":["Sanity-check/clamp the adjustment magnitude (e.g. reject |adj| beyond a plausible price bound) before calling `set_adjustment`","Fix the upstream scaling so the mantissa is in real price units, not scaled by an extra power of ten","Compile/use the high-precision build if legitimately large values are required","Add a validation step at ingestion that drops or flags quotes with out-of-range adjustment factors"],"exampleFix":"// before\nbuilder.set_adjustment(raw_index_price_scaled); // panics if beyond PriceRaw\n// after\nlet adj_f = raw_index_price_scaled.as_f64();\nassert!(adj_f.abs() < 1.0e9, \"implausible adjustment: {adj_f}\");\nbuilder.set_adjustment(Price::new(adj_f, adjustment_price.precision()));","handlingStrategy":"validation","validationCode":"// Rust: sanity-bound the adjustment before use\nassert!(adj.as_f64().abs() < 1.0e9, \"adjustment out of plausible range: {}\", adj.as_f64());","typeGuard":null,"tryCatchPattern":"let result = std::panic::catch_unwind(|| builder.set_adjustment(adj));","preventionTips":["Validate market-data magnitudes at ingestion (drop absurd quotes)","Verify unit scaling of upstream feeds (extra 10^k factors)","Use the high-precision build if large values are legitimate"],"tags":["rust","panic","overflow","fixed-point"],"backgroundTag":"value-out-of-range","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}