{"record":{"id":"06fa8b16ee8e2db6","repo":"nautechsystems/nautilus_trader","slug":"field-value-is-not-exactly-representable-with","errorCode":null,"errorMessage":"{field} {value} is not exactly representable with quantity precision {precision}","messagePattern":"(.+?) (.+?) is not exactly representable with quantity precision (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/execution/reconciliation.rs","lineNumber":285,"sourceCode":"fn validate_quantity_evidence(\n    value: Decimal,\n    precision: u8,\n    field: &str,\n    allow_zero: bool,\n) -> anyhow::Result<()> {\n    if allow_zero {\n        anyhow::ensure!(\n            value >= Decimal::ZERO,\n            \"{field} {value} must be non-negative\"\n        );\n    } else {\n        anyhow::ensure!(value > Decimal::ZERO, \"{field} {value} must be positive\");\n    }\n\n    let quantity = Quantity::from_decimal_dp(value, precision).with_context(|| {\n        format!(\"failed to represent {field} {value} with quantity precision {precision}\")\n    })?;\n    anyhow::ensure!(\n        quantity.as_decimal() == value,\n        \"{field} {value} is not exactly representable with quantity precision {precision}\",\n    );\n    Ok(())\n}\n\nfn validate_price_evidence(value: Decimal, precision: u8, field: &str) -> anyhow::Result<()> {\n    anyhow::ensure!(\n        value > Decimal::ZERO && value < Decimal::ONE,\n        \"{field} {value} must be greater than zero and less than one\",\n    );\n    let price = Price::from_decimal_dp(value, precision).with_context(|| {\n        format!(\"failed to represent {field} {value} with price precision {precision}\")\n    })?;\n    anyhow::ensure!(\n        price.as_decimal() == value,\n        \"{field} {value} is not exactly representable with price precision {precision}\",\n    );","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/execution/reconciliation.rs#L267-L303","documentation":"Domain Quantity values have fixed precision. After converting the decimal with Quantity::from_decimal_dp, the code verifies the round-trip is exact; this error fires when the provider value has more decimal places than the configured quantity precision and would be truncated or rounded.","triggerScenarios":"validate_quantity_evidence (via validate_order_row_values or validate_trade_values) receives a Decimal like 12.3456789 while the instrument's quantity precision is, say, 2 — quantity.as_decimal() != value.","commonSituations":"Polymarket sizes with more decimals than the instrument's tick/precision config; instrument precision configured too coarsely in the venue config; provider changing the number of decimals in size fields.","solutions":["Check the instrument's configured quantity precision and raise it to cover the provider's decimals if the venue truly supports them.","Verify the provider value against the market's size tick; sizes not matching the tick are suspect data.","Round only with an explicit, logged policy after confirming the venue accepts the rounded value — never silently.","Compare with the raw JSON string from the provider to confirm the extra decimals are real and not a parsing artifact."],"exampleFix":"// before\nlet precision = instrument.precision.quantity;\nvalidate_quantity_evidence(trade.size, precision, \"size\", false)?;\n// after\nlet precision = instrument.precision.quantity;\nif trade.size.fract().scale() > precision as u32 {\n    warn!(\"provider size {} exceeds instrument quantity precision {}; skipping\", trade.size, precision);\n    return Ok(());\n}\nvalidate_quantity_evidence(trade.size, precision, \"size\", false)?;","handlingStrategy":"validation","validationCode":"fn fits_precision(v: Decimal, precision: u8) -> bool {\n    v.fract().scale() <= precision as u32\n}","typeGuard":"fn exactly_representable_quantity(v: Decimal, precision: u8) -> Option<Quantity> {\n    Quantity::from_decimal_dp(v, precision).ok().filter(|q| q.as_decimal() == v)\n}","tryCatchPattern":"match validate_quantity_evidence(size, precision, \"size\", false) {\n    Ok(()) => (),\n    Err(e) if e.to_string().contains(\"representable\") => warn!(\"size {} exceeds precision {}; needs review\", size, precision),\n    Err(e) => return Err(e),\n}","preventionTips":["Set instrument quantity precision from the market's size tick metadata","Parse provider numbers as Decimal strings, never via f64","Log raw provider JSON when precision errors occur to distinguish data bugs from config bugs"],"tags":["rust","validation","decimal","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-14T05:17:10.506Z"}