{"record":{"id":"686aa4e398e58e25","repo":"nautechsystems/nautilus_trader","slug":"effective-raw-scale-should-fit-in-quantityraw","errorCode":null,"errorMessage":"effective raw scale should fit in QuantityRaw","messagePattern":"effective raw scale should fit in QuantityRaw","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/python/types/quantity.rs","lineNumber":398,"sourceCode":"            )))\n        }\n    }\n\n    fn __neg__(&self) -> Decimal {\n        self.as_decimal().neg()\n    }\n\n    fn __pos__(&self) -> Self {\n        *self\n    }\n\n    fn __abs__(&self) -> Self {\n        *self\n    }\n\n    fn __int__(&self) -> QuantityRaw {\n        let scale = QuantityRaw::try_from(raw_scale(self.precision))\n            .expect(\"effective raw scale should fit in QuantityRaw\");\n        self.raw / scale\n    }\n\n    fn __float__(&self) -> f64 {\n        self.as_f64()\n    }\n\n    #[pyo3(signature = (ndigits=None))]\n    fn __round__(&self, ndigits: Option<u32>) -> Decimal {\n        self.as_decimal()\n            .round_dp_with_strategy(ndigits.unwrap_or(0), RoundingStrategy::MidpointNearestEven)\n    }\n\n    fn __repr__(&self) -> String {\n        format!(\"{self:?}\")\n    }\n\n    fn __str__(&self) -> String {","sourceCodeStart":380,"sourceCodeEnd":416,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/python/types/quantity.rs#L380-L416","documentation":"Quantity's `__int__` (Python int() conversion) truncates the raw fixed-point value by dividing by 10^precision. The scale constant 10^precision is first converted into QuantityRaw (an i64/u64), and if the effective scale does not fit in that integer type the conversion fails and this panic is thrown. It guards an internal invariant of the fixed-point representation.","triggerScenarios":"Calling int(quantity) on a Quantity whose currency/price precision implies a raw scale (10^precision) larger than QuantityRaw::MAX, e.g. a very high precision value exposed through the Python bindings.","commonSituations":"Using extreme precision values (near or above the i64/u64 digit limit ~18-19 digits) when constructing instruments or prices, then converting to int in Python; test fixtures with unrealistic precision settings.","solutions":["Lower the precision used for the Quantity so 10^precision fits in QuantityRaw.","Use as_f64()/float() conversion instead of int() for high-precision quantities.","If high precision is genuinely needed, ensure the build uses the high-precision (i128) feature so QuantityRaw is wide enough."],"exampleFix":"// before\nq = Quantity.from_raw(123456789012345678901, precision=25)\nprint(int(q))  # panics\n// after\nq = Quantity.from_raw(123456789012345678901, precision=25)\nprint(int(float(q)))  # truncate via float, or use a lower precision","handlingStrategy":"validation","validationCode":"# Python side\nif quantity.precision > 18:  # 10**18 is near QuantityRaw (i64) limit\n    raise ValueError(\"precision too high for int() conversion\")\nint(quantity)","typeGuard":"def safe_int(q) -> int | None:\n    return None if q.precision > 18 else int(q)","tryCatchPattern":null,"preventionTips":["Keep instrument price precisions within realistic market ranges (<= 12 digits).","Prefer float(q) or q.as_f64() over int(q) for inspection.","Enable the high-precision feature if large precisions are required."],"tags":["rust","overflow","fixed-point","quantity"],"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"}