exchange.ModifyOrder
The exchange.ModifyOrder() function is used to modify an existing regular order, allowing you to modify the order's price and quantity. This function supports modifying other order attributes via additional parameters (depending on the support of the exchange API).
exchange.ModifyOrder(orderId, side, price, amount)Examples
-
Modify the price and quantity of a regular order.
javascriptfunction main() { // Create a limit buy order var id = exchange.CreateOrder("SOL_USDT.swap", "buy", 88, 1) Log("Original Order ID:", id) Sleep(2000) // Query the original order info var order = exchange.GetOrder(id) Log("Original Order Info:", order) Sleep(1000) // Modify the order's price and quantity var newId = exchange.ModifyOrder(id, "buy", 77, 2) Log("Modified Order ID:", newId) Sleep(2000) // Query the modified order info var newOrder = exchange.GetOrder(newId) Log("Modified Order Info:", newOrder) // Cancel the order exchange.CancelOrder(newId) }pythondef main(): # Create a limit buy order id = exchange.CreateOrder("SOL_USDT.swap", "buy", 88, 1) Log("Original Order ID:", id) Sleep(2000) # Query the original order info order = exchange.GetOrder(id) Log("Original Order Info:", order) Sleep(1000) # Modify the order's price and quantity newId = exchange.ModifyOrder(id, "buy", 77, 2) Log("Modified Order ID:", newId) Sleep(2000) # Query the modified order info newOrder = exchange.GetOrder(newId) Log("Modified Order Info:", newOrder) # Cancel the order exchange.CancelOrder(newId)rustfn main() { // Create a limit buy order let id = exchange.CreateOrder("SOL_USDT.swap", "buy", 88, 1).unwrap(); Log!("Original Order ID:", id); Sleep(2000); // Query the original order info let order = exchange.GetOrder(&id).unwrap(); Log!("Original Order Info:", order); Sleep(1000); // Modify the order's price and quantity let newId = exchange.ModifyOrder(&id, "buy", 77, 2).unwrap(); Log!("Modified Order ID:", newId); Sleep(2000); // Query the modified order info let newOrder = exchange.GetOrder(&newId).unwrap(); Log!("Modified Order Info:", newOrder); // Cancel the order let _ = exchange.CancelOrder(&newId); }c++void main() { // Create a limit buy order auto id = exchange.CreateOrder("SOL_USDT.swap", "buy", 88, 1); Log("Original Order ID:", id); Sleep(2000); // Query the original order info auto order = exchange.GetOrder(id); Log("Original Order Info:", order); Sleep(1000); // Modify the order's price and quantity auto newId = exchange.ModifyOrder(id, "buy", 77, 2); Log("Modified Order ID:", newId); Sleep(2000); // Query the modified order info auto newOrder = exchange.GetOrder(newId); Log("Modified Order Info:", newOrder); // Cancel the order exchange.CancelOrder(newId); } -
Use the additional parameter (option) to modify the order's price match mode.
javascriptfunction main() { // Create a limit buy order var id = exchange.CreateOrder("SOL_USDT.swap", "buy", 77, 1) Log("Original Order ID:", id) Sleep(2000) // Modify the order and set the price match mode to QUEUE_20 // Pass the additional parameter (JSON format) via the side parameter var option = {"priceMatch": "QUEUE_20"} var sideWithOption = "buy;" + JSON.stringify(option) var newId = exchange.ModifyOrder(id, sideWithOption, -1, 2) Log("Modified Order ID:", newId) Sleep(2000) // Query the modified order information var newOrder = exchange.GetOrder(newId) Log("Modified Order Info:", newOrder) // Cancel the order exchange.CancelOrder(newId) }pythonimport json def main(): # Create a limit buy order id = exchange.CreateOrder("SOL_USDT.swap", "buy", 77, 1) Log("Original Order ID:", id) Sleep(2000) # Modify the order and set the price match mode to QUEUE_20 # Pass the additional parameter (JSON format) via the side parameter option = {"priceMatch": "QUEUE_20"} sideWithOption = "buy;" + json.dumps(option) newId = exchange.ModifyOrder(id, sideWithOption, -1, 2) Log("Modified Order ID:", newId) Sleep(2000) # Query the modified order information newOrder = exchange.GetOrder(newId) Log("Modified Order Info:", newOrder) # Cancel the order exchange.CancelOrder(newId)rustfn main() { // Create a limit buy order let id = exchange.CreateOrder("SOL_USDT.swap", "buy", 77, 1).unwrap(); Log!("Original Order ID:", id); Sleep(2000); // Modify the order and set the price match mode to QUEUE_20 // Pass the additional parameter (JSON format) via the side parameter; Rust does not support JSON.stringify, so construct the JSON text directly using a raw string let option = r#"{"priceMatch": "QUEUE_20"}"#; let sideWithOption = format!("buy;{}", option); let newId = exchange.ModifyOrder(&id, &sideWithOption, -1, 2).unwrap(); Log!("Modified Order ID:", newId); Sleep(2000); // Query the modified order information let newOrder = exchange.GetOrder(&newId).unwrap(); Log!("Modified Order Info:", newOrder); // Cancel the order let _ = exchange.CancelOrder(&newId); }c++void main() { // Create a limit buy order auto id = exchange.CreateOrder("SOL_USDT.swap", "buy", 77, 1); Log("Original Order ID:", id); Sleep(2000); // Modify the order and set the price match mode to QUEUE_20 // Pass the additional parameter (JSON format) via the side parameter json option = R"({"priceMatch": "QUEUE_20"})"_json; string sideWithOption = "buy;" + option.dump(); auto newId = exchange.ModifyOrder(id, sideWithOption, -1, 2); Log("Modified Order ID:", newId); Sleep(2000); // Query the modified order information auto newOrder = exchange.GetOrder(newId); Log("Modified Order Info:", newOrder); // Cancel the order exchange.CancelOrder(newId); }
Returns
| Type | Description |
string / null value | Returns the order ID when the order modification succeeds, and returns a null value when the modification fails. The returned order ID may be the same as the original order ID or different, depending on the exchange API implementation. Some exchanges return a new order ID after modifying the order, while others keep the order ID unchanged. |
Arguments
| Name | Type | Required | Description |
orderId | string | Yes | The |
side | string | Yes | The For spot exchange objects, the available values for the For futures exchange objects, the available values for the Supports additional parameters (option): Additional parameters can be passed via the For example: Additional parameters are used to modify other order attributes (such as the price match mode, etc.); the specific parameters supported depend on the exchange API. |
price | number | Yes | The |
amount | number | Yes | The |
See Also
Remarks
The order ID returned by the exchange.ModifyOrder() function may behave differently depending on the exchange API implementation. Some exchange APIs return an updated order ID, while others keep it unchanged. It is recommended to use the returned new order ID for subsequent operations.
The exchange.ModifyOrder() function does not validate the validity of parameters according to the exchange interface rules, but instead submits the parameters directly to the exchange API. When invalid parameters are passed in (such as a price or quantity of -1), the parameters may be ignored by the exchange, and the order will retain its original attributes unchanged.
Supports passing additional parameters (option) via the side parameter to modify other order attributes. Additional parameters must be merged with the side parameter before being passed in, in the format "side;{JSON object}" (recommended) or "side;key=value" (URL-encoded format). For example, to modify the price match mode: "buy;{\"priceMatch\":\"QUEUE_20\"}".
For modifying market orders among regular orders, you need to check specifically whether the exchange API supports it. Some exchanges do not support modifying market orders.
When modifying an order, the order's other attributes (such as order type, position mode, account mode, leverage, order time-in-force rules, etc.) usually retain the settings of the original order. If you need to modify these attributes, they can be passed in via additional parameters (option), provided the exchange API supports it.
Certain exchange APIs may convert an order into a market order when the price parameter is not received (price is -1 or null). For spot market buy orders, note that the unit of the order quantity may be the amount rather than the number of coins.
Support for the order modification feature depends on the specific exchange; some exchanges may not support the order modification feature, or may only support modifying certain parameters. Please consult the API documentation of the corresponding exchange before use.