exchange.ModifyConditionOrder
The exchange.ModifyConditionOrder() function is used to modify an existing conditional order, allowing modification of the order amount, trigger condition, and execution price of the conditional order. It supports modifying other properties of the conditional order through additional parameters (depending on the specific support of the exchange API).
exchange.ModifyConditionOrder(orderId, side, amount, condition)Examples
-
Modify the quantity and trigger conditions of a conditional order.
javascriptfunction main() { // Create a take-profit conditional order var condition = { ConditionType: ORDER_CONDITION_TYPE_TP, TpTriggerPrice: 77, TpOrderPrice: 76 } var id = exchange.CreateConditionOrder("SOL_USDT.swap", "buy", 1, condition) Log("Original Condition Order ID:", id) Sleep(2000) // Query the original conditional order information var order = exchange.GetConditionOrder(id) Log("Original Condition Order Info:", order) Sleep(1000) // Modify the quantity and trigger conditions of the conditional order var newCondition = { ConditionType: ORDER_CONDITION_TYPE_TP, TpTriggerPrice: 75, TpOrderPrice: 71 } var newId = exchange.ModifyConditionOrder(id, "buy", 2, newCondition) Log("Modified Condition Order ID:", newId) Sleep(2000) // Query the modified conditional order information var newOrder = exchange.GetConditionOrder(newId) Log("Modified Condition Order Info:", newOrder) // Cancel the conditional order exchange.CancelConditionOrder(newId) }pythondef main(): # Create a take-profit conditional order condition = { "ConditionType": ORDER_CONDITION_TYPE_TP, "TpTriggerPrice": 77, "TpOrderPrice": 76 } id = exchange.CreateConditionOrder("SOL_USDT.swap", "buy", 1, condition) Log("Original Condition Order ID:", id) Sleep(2000) # Query the original conditional order information order = exchange.GetConditionOrder(id) Log("Original Condition Order Info:", order) Sleep(1000) # Modify the quantity and trigger conditions of the conditional order newCondition = { "ConditionType": ORDER_CONDITION_TYPE_TP, "TpTriggerPrice": 75, "TpOrderPrice": 71 } newId = exchange.ModifyConditionOrder(id, "buy", 2, newCondition) Log("Modified Condition Order ID:", newId) Sleep(2000) # Query the modified conditional order information newOrder = exchange.GetConditionOrder(newId) Log("Modified Condition Order Info:", newOrder) # Cancel the conditional order exchange.CancelConditionOrder(newId)rustfn main() { // Create a take-profit conditional order let condition = OrderCondition { ConditionType: ORDER_CONDITION_TYPE_TP, TpTriggerPrice: 77.0, TpOrderPrice: 76.0, ..Default::default() }; let id = exchange.CreateConditionOrder("SOL_USDT.swap", "buy", 1, &condition).unwrap(); Log!("Original Condition Order ID:", id); Sleep(2000); // Query the original conditional order information let order = exchange.GetConditionOrder(&id); Log!("Original Condition Order Info:", order); Sleep(1000); // Modify the quantity and trigger conditions of the conditional order let newCondition = OrderCondition { ConditionType: ORDER_CONDITION_TYPE_TP, TpTriggerPrice: 75.0, TpOrderPrice: 71.0, ..Default::default() }; let newId = exchange.ModifyConditionOrder(&id, "buy", 2, &newCondition).unwrap(); Log!("Modified Condition Order ID:", newId); Sleep(2000); // Query the modified conditional order information let newOrder = exchange.GetConditionOrder(&newId); Log!("Modified Condition Order Info:", newOrder); // Cancel the conditional order let _ = exchange.CancelConditionOrder(&newId); }c++void main() { // Create a take-profit conditional order OrderCondition condition = {.ConditionType = ORDER_CONDITION_TYPE_TP, .TpTriggerPrice = 77, .TpOrderPrice = 76}; auto id = exchange.CreateConditionOrder("SOL_USDT.swap", "buy", 1, condition); Log("Original Condition Order ID:", id); Sleep(2000); // Query the original conditional order information auto order = exchange.GetConditionOrder(id); Log("Original Condition Order Info:", order); Sleep(1000); // Modify the quantity and trigger conditions of the conditional order OrderCondition newCondition = {.ConditionType = ORDER_CONDITION_TYPE_TP, .TpTriggerPrice = 75, .TpOrderPrice = 71}; auto newId = exchange.ModifyConditionOrder(id, "buy", 2, newCondition); Log("Modified Condition Order ID:", newId); Sleep(2000); // Query the modified conditional order information auto newOrder = exchange.GetConditionOrder(newId); Log("Modified Condition Order Info:", newOrder); // Cancel the conditional order exchange.CancelConditionOrder(newId); } -
Use the additional parameter (option) to modify the trigger price type of a conditional order.
javascriptfunction main() { // Create a take-profit conditional order var condition = { ConditionType: ORDER_CONDITION_TYPE_TP, TpTriggerPrice: 77, TpOrderPrice: 76 } var id = exchange.CreateConditionOrder("SOL_USDT.swap", "buy", 1, condition) Log("Original Condition Order ID:", id) Sleep(2000) // Modify the conditional order and set the trigger price type to index price (index) // Pass the additional parameter via the side parameter (in JSON format) var option = {"newTpTriggerPxType": "index"} var sideWithOption = "buy;" + JSON.stringify(option) var newCondition = { ConditionType: ORDER_CONDITION_TYPE_TP, TpTriggerPrice: 75, TpOrderPrice: 71 } var newId = exchange.ModifyConditionOrder(id, sideWithOption, 2, newCondition) Log("Modified Condition Order ID:", newId) Sleep(2000) // Query the modified conditional order information var newOrder = exchange.GetConditionOrder(newId) Log("Modified Condition Order Info:", newOrder) // Cancel the conditional order exchange.CancelConditionOrder(newId) }pythonimport json def main(): # Create a take-profit conditional order condition = { "ConditionType": ORDER_CONDITION_TYPE_TP, "TpTriggerPrice": 77, "TpOrderPrice": 76 } id = exchange.CreateConditionOrder("SOL_USDT.swap", "buy", 1, condition) Log("Original Condition Order ID:", id) Sleep(2000) # Modify the conditional order and set the trigger price type to index price (index) # Pass the additional parameter via the side parameter (in JSON format) option = {"newTpTriggerPxType": "index"} sideWithOption = "buy;" + json.dumps(option) newCondition = { "ConditionType": ORDER_CONDITION_TYPE_TP, "TpTriggerPrice": 75, "TpOrderPrice": 71 } newId = exchange.ModifyConditionOrder(id, sideWithOption, 2, newCondition) Log("Modified Condition Order ID:", newId) Sleep(2000) # Query the modified conditional order information newOrder = exchange.GetConditionOrder(newId) Log("Modified Condition Order Info:", newOrder) # Cancel the conditional order exchange.CancelConditionOrder(newId)rustfn main() { // Create a take-profit conditional order let condition = OrderCondition { ConditionType: ORDER_CONDITION_TYPE_TP, TpTriggerPrice: 77.0, TpOrderPrice: 76.0, ..Default::default() }; let id = exchange.CreateConditionOrder("SOL_USDT.swap", "buy", 1, &condition).unwrap(); Log!("Original Condition Order ID:", id); Sleep(2000); // Modify the conditional order and set the trigger price type to index price (index) // Pass the additional parameter via the side parameter (in JSON format; Rust has no JSON serialization here, so a raw string literal is used directly) let sideWithOption = r#"buy;{"newTpTriggerPxType": "index"}"#; let newCondition = OrderCondition { ConditionType: ORDER_CONDITION_TYPE_TP, TpTriggerPrice: 75.0, TpOrderPrice: 71.0, ..Default::default() }; let newId = exchange.ModifyConditionOrder(&id, sideWithOption, 2, &newCondition).unwrap(); Log!("Modified Condition Order ID:", newId); Sleep(2000); // Query the modified conditional order information let newOrder = exchange.GetConditionOrder(&newId); Log!("Modified Condition Order Info:", newOrder); // Cancel the conditional order let _ = exchange.CancelConditionOrder(&newId); }c++void main() { // Create a take-profit conditional order OrderCondition condition = {.ConditionType = ORDER_CONDITION_TYPE_TP, .TpTriggerPrice = 77, .TpOrderPrice = 76}; auto id = exchange.CreateConditionOrder("SOL_USDT.swap", "buy", 1, condition); Log("Original Condition Order ID:", id); Sleep(2000); // Modify the conditional order and set the trigger price type to index price (index) // Pass the additional parameter via the side parameter (in JSON format) json option = R"({"newTpTriggerPxType": "index"})"_json; string sideWithOption = "buy;" + option.dump(); OrderCondition newCondition = {.ConditionType = ORDER_CONDITION_TYPE_TP, .TpTriggerPrice = 75, .TpOrderPrice = 71}; auto newId = exchange.ModifyConditionOrder(id, sideWithOption, 2, newCondition); Log("Modified Condition Order ID:", newId); Sleep(2000); // Query the modified conditional order information auto newOrder = exchange.GetConditionOrder(newId); Log("Modified Condition Order Info:", newOrder); // Cancel the conditional order exchange.CancelConditionOrder(newId); }
Returns
| Type | Description |
string / null value | When the conditional order is successfully modified, the conditional order ID is returned; when the modification fails, a null value is returned. The returned conditional order ID may be the same as the original conditional order ID, or it may be different, depending on the specific implementation of the exchange API. Some exchanges return a new conditional order ID after modifying the conditional order, while some exchanges keep the conditional 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 Additional parameters (option) supported: Additional parameters can be passed through the For example: Additional parameters are used to modify other properties of the conditional order (such as the trigger price type, etc.), and the specific parameters supported depend on the exchange API. |
amount | number | Yes | The |
condition | object | Yes | The
|
See Also
Condition exchange.CreateConditionOrder exchange.CancelConditionOrder exchange.GetConditionOrder exchange.GetConditionOrders
Remarks
The conditional order ID returned by the exchange.ModifyConditionOrder() function may exhibit different behaviors depending on the exchange API implementation. Some exchange APIs return an updated conditional order ID, while others keep it unchanged. It is recommended to use the returned new conditional order ID for subsequent operations.
The exchange.ModifyConditionOrder() function does not validate the validity of the parameters according to the exchange interface rules, but submits the parameters directly to the exchange API. When invalid parameters are passed in (such as an amount of -1), the parameter may be ignored by the exchange, and the conditional order retains its original properties unchanged.
Passing additional parameters (option) through the side parameter is supported, used to modify other properties of the conditional order. The additional parameters need to be merged with the side parameter, in the format "side;{JSON object}" (recommended) or "side;key=value" (URL-encoded format). For example, to modify the trigger price type: "buy;{\"newTpTriggerPxType\":\"index\"}".
For market order modification of conditional orders, you need to specifically check whether the exchange API supports it. Setting TpOrderPrice or SlOrderPrice in the condition parameter to -1 indicates a market order.
When modifying a conditional order, other properties of the conditional order (such as condition type, position mode, account mode, leverage, etc.) are usually retained from the original conditional order's settings. If you need to modify these properties, you can pass them in through additional parameters (option), provided that the exchange API supports it.
The trigger price type can be modified through additional parameters, for example, changing the trigger price type from the last price (last) to the index price (index) or the mark price (mark). The specific parameter names and support status depend on the exchange API documentation.
The support for the conditional order modification feature depends on the specific exchange. Some exchanges may not support the conditional order modification feature, or may only support modifying some parameters. Please consult the API documentation of the corresponding exchange before use.