{"record":{"id":"e33a462893397831","repo":"nautechsystems/nautilus_trader","slug":"invalid-venue-order-id-id","errorCode":null,"errorMessage":"Invalid venue order ID: {id}","messagePattern":"Invalid venue order ID: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/execution.rs","lineNumber":2587,"sourceCode":"    }\n}\n\nfn build_cancel_replace_params(\n    cmd: &ModifyOrder,\n    order: &impl Order,\n    quantity: Quantity,\n    use_gtd: bool,\n) -> anyhow::Result<CancelReplaceOrderParams> {\n    let binance_side = BinanceSide::try_from(order.order_side())?;\n    let binance_order_type = order_type_to_binance_spot(order.order_type(), false)?;\n    let binance_tif = time_in_force_to_binance_spot(order.time_in_force(), use_gtd)?;\n\n    let cancel_order_id: Option<i64> = cmd\n        .venue_order_id\n        .map(|id| {\n            id.inner()\n                .parse::<i64>()\n                .map_err(|_| anyhow::anyhow!(\"Invalid venue order ID: {id}\"))\n        })\n        .transpose()?;\n\n    let client_id_str = encode_broker_id(&cmd.client_order_id, BINANCE_NAUTILUS_SPOT_BROKER_ID);\n\n    Ok(CancelReplaceOrderParams {\n        symbol: cmd.instrument_id.symbol.to_string(),\n        side: binance_side,\n        order_type: binance_order_type,\n        cancel_replace_mode: BinanceCancelReplaceMode::StopOnFailure,\n        time_in_force: Some(binance_tif),\n        quantity: Some(quantity.to_string()),\n        quote_order_qty: None,\n        price: cmd.price.map(|p| p.to_string()),\n        cancel_order_id,\n        cancel_orig_client_order_id: if cancel_order_id.is_none() {\n            Some(client_id_str.clone())\n        } else {","sourceCodeStart":2569,"sourceCodeEnd":2605,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/a4b06ed870971b5671d12754ea138a3ab99b1dec/crates/adapters/binance/src/spot/execution.rs#L2569-L2605","documentation":"`build_cancel_replace_params` (used by the WS modify path) must convert the `ModifyOrder.venue_order_id` string into an `i64`, because Binance Spot venue order IDs are numeric integers. If the ID does not parse as an integer, the adapter bails with 'Invalid venue order ID: {id}' and the modify never reaches Binance.","triggerScenarios":"A `ModifyOrder` command carrying a `venue_order_id` whose string is not a pure integer — e.g. a broker-prefixed/encoded ID, an ID minted by another venue or by a backtest/simulation, or a manually constructed ID — submitted while WS trading is active.","commonSituations":"Replaying simulated order objects into live trading; custom code that fabricates or decorates venue order IDs; cross-venue strategies reusing one ModifyOrder builder; modifying an order whose cached venue_order_id was written by a different adapter.","solutions":["Always source `venue_order_id` from the venue acknowledgment (OrderAccepted/Updated) or the cached order — never construct or transform it yourself","If you carry IDs through your own layer, pass them through verbatim and verify they are numeric before live use","Confirm the order actually belongs to Binance Spot and was not created by another venue's execution client"],"exampleFix":"# before\nmodify = ModifyOrder(\n    ...,\n    client_order_id=order.client_order_id,\n    venue_order_id=VenueOrderId(f\"BNB-{order.client_order_id}\"),  # non-numeric -> Invalid venue order ID\n    ...,\n)\n\n# after\nmodify = ModifyOrder(\n    ...,\n    client_order_id=order.client_order_id,\n    venue_order_id=order.venue_order_id,  # numeric ID exactly as returned by Binance\n    ...,\n)","handlingStrategy":"validation","validationCode":"# Python: guard before submitting a WS-path modify\nvenue_id = order.venue_order_id\nif venue_id is not None and not str(venue_id).lstrip(\"-\").isdigit():\n    self.log.error(\n        f\"Refusing to modify: venue_order_id {venue_id} is not a Binance numeric ID\"\n    )\n    return","typeGuard":"# Python\ndef is_binance_spot_venue_order_id(venue_order_id) -> bool:\n    \"\"\"Binance Spot venue order IDs are integer strings.\"\"\"\n    try:\n        int(str(venue_order_id))\n        return True\n    except ValueError:\n        return False","tryCatchPattern":"# Python: modify errors surface as rejections/events; gate on the cached order first\nif order.venue_order_id is None or not is_binance_spot_venue_order_id(order.venue_order_id):\n    self.log.error(\"venue_order_id missing or malformed; skipping modify\")\n    return\nself.request(modify_command)","preventionTips":["Never fabricate, prefix, or reformat venue_order_id — pass through the exact string Binance assigned","Source venue_order_id from the venue acknowledgment event or the cache, not from your own ID scheme","Validate that IDs are numeric in any persistence layer that round-trips orders between environments (sim → live)","Keep one ModifyOrder construction path per venue to avoid cross-venue ID mixups"],"tags":["binance-spot","modify-order","venue-order-id","parsing","validation","nautilustrader"],"backgroundTag":"invalid-order-id-format","analyzedSha":"a4b06ed870971b5671d12754ea138a3ab99b1dec","analyzedAt":"2026-08-16T22:54:50.089Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}