{"record":{"id":"a91d93e9119aa0ae","repo":"nautechsystems/nautilus_trader","slug":"replacement-venue-leg-quantity-does-not-match-s","errorCode":null,"errorMessage":"replacement venue-leg quantity {} does not match signed quantity {}","messagePattern":"replacement venue-leg quantity (.+?) does not match signed quantity (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/execution/reports.rs","lineNumber":715,"sourceCode":"        )?;\n\n        let mut modify_fill_offsets = AHashMap::new();\n        let mut rejected_replacements = AHashSet::new();\n\n        for report in &mut reports {\n            let promotion = self\n                .ws_dispatch_state\n                .lock()\n                .pending_modify_promotion(report.venue_order_id);\n            let Some(promotion) = promotion else {\n                continue;\n            };\n\n            let context = self\n                .order_contexts\n                .get(&promotion.old_venue_order_id)\n                .context(\"pending modification has no old-leg context\")?;\n            anyhow::ensure!(\n                report.quantity == promotion.leg_quantity,\n                \"replacement venue-leg quantity {} does not match signed quantity {}\",\n                report.quantity,\n                promotion.leg_quantity,\n            );\n            anyhow::ensure!(\n                report.price == Some(promotion.price),\n                \"replacement venue-leg price {:?} does not match signed price {}\",\n                report.price,\n                promotion.price,\n            );\n            anyhow::ensure!(\n                report.order_side == Some(context.identity.order_side),\n                \"replacement venue-leg side {:?} does not match logical order side {}\",\n                report.order_side,\n                context.identity.order_side,\n            );\n            let cached_order = self","sourceCodeStart":697,"sourceCodeEnd":733,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/execution/reports.rs#L697-L733","documentation":"During pending-modification (replace) promotion in generate_order_status_reports_impl, the report fetched for the replacement venue leg must have exactly the quantity that was signed for the replacement. This ensure! fires when the venue reports a different leg quantity than promotion.leg_quantity, meaning venue state diverged from what the adapter signed/submitted.","triggerScenarios":"A pending modification is promoted to a real order status report, and the venue's returned report.quantity differs from the quantity captured in the signed promotion payload.","commonSituations":"Venue partially filled or amended the replacement order before the poll; race between submit of replacement and status poll; adapter bug in quantity unit conversion (e.g. lots vs raw) when building the promotion.","solutions":["Re-poll the order status; if transient, the next poll may match after venue settles","Verify quantity conversion when building the promotion payload (precision/scale)","Check venue UI/API for manual edits to the replacement order","Log and inspect promotion.leg_quantity vs venue response to find the divergence source"],"exampleFix":"// before\nlet promotion = sign_replacement(order, qty_as_f64_rounded)?; // rounding drifted\n// after\nlet promotion = sign_replacement(order, order.quantity())?; // exact Decimal from order","handlingStrategy":"validation","validationCode":"let signed_qty = promotion.leg_quantity;\nanyhow::ensure!(signed_qty == order.quantity(), \"promotion quantity must match logical order quantity\");","typeGuard":"fn promotion_quantity_valid(promotion: &Promotion, report: &OrderStatusReport) -> bool {\n    report.quantity == promotion.leg_quantity\n}","tryCatchPattern":"match reports.iter().find(|r| r.venue_order_id == new_void) {\n    Some(r) if r.quantity != promotion.leg_quantity => warn!(\"venue diverged from signed replace; re-poll\"),\n    _ => {},\n}","preventionTips":["Build promotion payloads from the order's Decimal quantity directly; never round via f64","After a replace, allow a short settle delay before promoting status reports","Alert on repeated mismatches — they indicate venue-side manual edits or missed events"],"tags":["rust","order-modification","quantity","venue-mismatch"],"backgroundTag":"internal-invariant-violation","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"}