{"record":{"id":"2494e27e51064a7a","repo":"nautechsystems/nautilus_trader","slug":"size-precision-precision-exceeds-maximum-max-de","errorCode":null,"errorMessage":"size precision {precision} exceeds maximum {MAX_DECIMALS}","messagePattern":"size precision (.+?) exceeds maximum (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/lighter/src/common/parse.rs","lineNumber":113,"sourceCode":"    );\n    let decimal =\n        Decimal::from_str(value).map_err(|e| anyhow::anyhow!(\"invalid price `{value}`: {e}\"))?;\n    Price::from_decimal_dp(decimal, precision)\n        .map_err(|e| anyhow::anyhow!(\"invalid price `{value}` at precision {precision}: {e}\"))\n}\n\n/// Converts a decimal string into a non-negative Nautilus [`Quantity`].\n///\n/// Zero is allowed because Lighter sends zero-size book levels to delete\n/// existing orders.\n///\n/// # Errors\n///\n/// Returns an error if the string is not a decimal, if `precision` exceeds\n/// [`MAX_DECIMALS`], if the value is negative, or if the resulting quantity\n/// is out of range.\npub fn parse_quantity(value: &str, precision: u8) -> anyhow::Result<Quantity> {\n    anyhow::ensure!(\n        precision <= MAX_DECIMALS,\n        \"size precision {precision} exceeds maximum {MAX_DECIMALS}\",\n    );\n    let decimal =\n        Decimal::from_str(value).map_err(|e| anyhow::anyhow!(\"invalid quantity `{value}`: {e}\"))?;\n    anyhow::ensure!(decimal.is_sign_positive(), \"negative quantity `{value}`\");\n    Quantity::from_decimal_dp(decimal, precision)\n        .map_err(|e| anyhow::anyhow!(\"invalid quantity `{value}` at precision {precision}: {e}\"))\n}\n\n/// Converts a [`Decimal`] into a Nautilus [`Price`] at the requested precision.\n///\n/// Use this when the wire value has already been deserialized as a [`Decimal`]\n/// (the standard pattern for model fields tagged with `deserialize_decimal`).\n///\n/// # Errors\n///\n/// Returns an error if `precision` exceeds [`MAX_DECIMALS`] or if the value","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/lighter/src/common/parse.rs#L95-L131","documentation":"parse_quantity converts a decimal string into a non-negative Nautilus Quantity at a requested precision. Nautilus Quantity is fixed-precision with a maximum of MAX_DECIMALS decimal places; any precision argument above that cannot be represented and is rejected before parsing begins.","triggerScenarios":"Calling parse_quantity with a precision greater than MAX_DECIMALS — e.g. passing size_decimals=20 from market metadata, or a hard-coded literal that exceeds the fixed-precision limit.","commonSituations":"A Lighter market reporting unusually high size_decimals; copy-pasted precision constants from another venue; confusing bit-width (e.g. 32/64) with decimal places when wiring the precision parameter.","solutions":["Validate the market's size_decimals against MAX_DECIMALS when loading instrument definitions and skip unsupported markets.","Pass size_decimals from the orderBookDetails response rather than hard-coded values.","Clamp with `precision.min(MAX_DECIMALS)` only if truncating to representable decimals is acceptable for your strategy.","If you see this for a real market, the market cannot be modeled in Nautilus fixed-precision; exclude it."],"exampleFix":"// before\nlet qty = parse_quantity(raw, size_decimals)?;\n// after\nanyhow::ensure!(size_decimals <= MAX_DECIMALS, \"unsupported size precision\");\nlet qty = parse_quantity(raw, size_decimals)?;","handlingStrategy":"validation","validationCode":"fn precision_supported(precision: u8) -> bool {\n    precision <= MAX_DECIMALS\n}","typeGuard":null,"tryCatchPattern":"match parse_quantity(raw, precision) {\n    Ok(q) => q,\n    Err(e) if e.to_string().contains(\"exceeds maximum\") => {\n        tracing::error!(\"size precision {precision} unsupported; skipping instrument\");\n        return Ok(None);\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Validate size_decimals from orderBookDetails when the instrument is loaded","Pass precision from parsed market metadata, never hard-coded literals","Exclude markets whose size precision exceeds Nautilus fixed-precision support","Distinguish decimal places from bit-width when wiring the precision argument"],"tags":["rust","parsing","validation","quantity","precision"],"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-14T00:17:10.932Z"}