{"record":{"id":"8535a20f9513759e","repo":"nautechsystems/nautilus_trader","slug":"order-modification-rejected-reason","errorCode":null,"errorMessage":"Order modification rejected: {reason}","messagePattern":"Order modification rejected: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/bitmex/src/http/client.rs","lineNumber":2000,"sourceCode":"        }\n\n        if let Some(price) = price {\n            params.price(price.as_f64());\n        }\n\n        if let Some(trigger_price) = trigger_price {\n            params.stop_px(trigger_price.as_f64());\n        }\n\n        let params = params.build().map_err(|e| anyhow::anyhow!(e))?;\n\n        let order: BitmexOrder = self.inner.amend_order_response(params).await?;\n\n        if order.ord_status == Some(BitmexOrderStatus::Rejected) {\n            let reason = order\n                .ord_rej_reason\n                .map_or_else(|| \"No reason provided\".to_string(), |r| r.to_string());\n            anyhow::bail!(\"Order modification rejected: {reason}\");\n        }\n\n        let instrument = self.instrument_from_cache(instrument_id.symbol.inner())?;\n        let ts_init = self.generate_ts_init();\n\n        parse_order_status_report(&order, &instrument, &self.order_type_cache, ts_init)\n    }\n\n    /// Query a single order by client order ID or venue order ID.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if:\n    /// - Credentials are missing.\n    /// - The request fails.\n    /// - The API returns an error.\n    pub async fn query_order(\n        &self,","sourceCodeStart":1982,"sourceCodeEnd":2018,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/bitmex/src/http/client.rs#L1982-L2018","documentation":"Raised by modify_order when BitMEX accepts the amend request but returns an order whose ordStatus is 'Rejected'. The adapter maps this venue-level rejection into a Rust error, using ordRejReason if present (otherwise 'No reason provided'). The request technically succeeded at HTTP level but the modification was refused by the venue.","triggerScenarios":"Amending an order in a way BitMEX rejects: modifying a filled/canceled order, changing quantity/price to invalid values, or amending during certain market states. Any amend response with ordStatus==Rejected triggers it.","commonSituations":"Race conditions where the order fills just before the amend arrives; price/qty outside instrument limits; amending orders that are already terminal.","solutions":["Inspect the returned reason string in the error message to identify the venue's rejection cause","Re-query the order status to confirm its current state before retrying the amend","Validate the new quantity/price against the instrument's limits before calling modify_order","Handle the race where the order has already filled — treat as a no-op or cancel flow"],"exampleFix":"// before\nlet report = client.modify_order(instrument_id, None, Some(vid), Some(new_qty), None, None).await?;\n// after\nlet current = client.request_order_status_report(instrument_id, None, Some(vid)).await?;\nif current.order_status != OrderStatus::Accepted { return Ok(current); }\nlet report = client.modify_order(instrument_id, None, Some(vid), Some(new_qty), None, None).await?;","handlingStrategy":"try-catch","validationCode":"let current = client.request_order_status_report(instrument_id, client_order_id.clone(), venue_order_id.clone()).await?;\nif current.order_status == OrderStatus::Filled || current.order_status == OrderStatus::Canceled {\n    return Ok(current); // nothing to amend\n}","typeGuard":"fn amendable(report: &OrderStatusReport) -> bool {\n    matches!(report.order_status, OrderStatus::Accepted | OrderStatus::PartiallyFilled)\n}","tryCatchPattern":"match client.modify_order(...).await {\n    Ok(report) => { /* handle */ }\n    Err(e) if e.to_string().starts_with(\"Order modification rejected:\") => {\n        let reason = e.to_string();\n        // re-query order state and decide: retry, cancel, or alert\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Re-check order status before amending to avoid racing fills","Validate new quantity/price against instrument tick size and limits","Log the venue rejection reason from the error message for post-mortem"],"tags":["rust","bitmex","order-rejected","venue-error"],"backgroundTag":"api-error-response","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"}