exchange.ModifyConditionOrder
Modifies an existing conditional order, including its order quantity, trigger condition and execution price. Other properties of the conditional order can also be modified through additional parameters, if the exchange API supports it.
exchange.ModifyConditionOrder(orderId, side, amount, condition)
exchange.ModifyConditionOrder(orderId, side, amount, condition, options)Examples
-
Modifies 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 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 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 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 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 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 let newOrder = exchange.GetConditionOrder(&newId); Log!("Modified Condition Order Info:", newOrder); // Cancel the conditional order let _ = exchange.CancelConditionOrder(&newId); } -
Change the trigger price type of a conditional order through the extra parameter (option).
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 the index price (index): exchange-specific parameters are passed in the last object parameter var newCondition = { ConditionType: ORDER_CONDITION_TYPE_TP, TpTriggerPrice: 75, TpOrderPrice: 71 } var newId = exchange.ModifyConditionOrder(id, "buy", 2, newCondition, {newTpTriggerPxType: "index"}) Log("Modified Condition Order ID:", newId) Sleep(2000) // Query the modified conditional order 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) # Modify the conditional order and set the trigger price type to the index price (index): exchange-specific parameters are passed in the last object parameter newCondition = { "ConditionType": ORDER_CONDITION_TYPE_TP, "TpTriggerPrice": 75, "TpOrderPrice": 71 } newId = exchange.ModifyConditionOrder(id, "buy", 2, newCondition, {"newTpTriggerPxType": "index"}) Log("Modified Condition Order ID:", newId) Sleep(2000) # Query the modified conditional order 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 the index price (index): in Rust, use the function with the WithOptions suffix to pass the object parameter let opts = JSONParse(r#"{"newTpTriggerPxType": "index"}"#).unwrap(); let newCondition = OrderCondition { ConditionType: ORDER_CONDITION_TYPE_TP, TpTriggerPrice: 75.0, TpOrderPrice: 71.0, ..Default::default() }; let newId = exchange.ModifyConditionOrderWithOptions(&id, "buy", 2, &newCondition, &opts).unwrap(); Log!("Modified Condition Order ID:", newId); Sleep(2000); // Query the modified conditional order let newOrder = exchange.GetConditionOrder(&newId); Log!("Modified Condition Order Info:", newOrder); // Cancel the conditional order let _ = exchange.CancelConditionOrder(&newId); }
Returns
| Type | Description |
string / null value | Returns the conditional order Id if the modification succeeds, or a null value if it fails. The returned ID may be the same as the original conditional order ID or a different one, depending on the exchange API. Some exchanges return a new conditional order ID after a modification, while others keep the same ID. |
Arguments
| Name | Type | Required | Description |
orderId | string | Yes | The ID of the conditional order to modify. It uses the same format as the conditional order ID returned by the |
side | string | Yes | Trade direction. For spot: |
amount | number | Yes | The new order quantity of the conditional order. It must be greater than 0. An invalid value such as -1 causes an error and returns a null value. For futures exchange objects, the order quantity parameter |
condition | object | Yes | The new trigger condition and execution price of the conditional order. See |
options | object | No | Exchange-specific parameters. The key-value pairs in this object are passed to the exchange unchanged, for example |
See Also
Condition exchange.CreateConditionOrder exchange.CancelConditionOrder exchange.GetConditionOrder exchange.GetConditionOrders
Remarks
The condition order ID returned by the exchange.ModifyConditionOrder() function may vary depending on each exchange's API implementation: some exchange APIs return an updated condition order ID, while others keep it unchanged. It is recommended to use the newly returned condition order ID for subsequent operations.
The exchange.ModifyConditionOrder() function validates the parameters first: the quantity must be greater than 0, and the trigger prices and execution prices required by the selected condition type cannot be 0. If validation fails, an error is reported and a null value is returned, and nothing is submitted to the exchange.
Exchange-specific parameters (option) are passed in through the last object parameter and are used to modify other attributes of the condition order, for example modifying the trigger price type: exchange.ModifyConditionOrder(id, "buy", 2, condition, {newTpTriggerPxType: "index"}). Rust uses exchange.ModifyConditionOrderWithOptions().
Setting TpOrderPrice or SlOrderPrice in the condition parameter to -1 means the order is executed at market price once triggered. Whether a modification can switch between limit and market depends on the exchange: some exchanges (e.g. Lighter) do not allow changing the limit/market type, and passing -1 for a limit condition order or a positive execution price for a market condition order will report an error. In that case, the order must be canceled and recreated. See each exchange's page for details.
When modifying a condition order, its other attributes (such as condition type, position mode, account mode, leverage, etc.) usually follow the settings of the original condition order. To modify these attributes, pass them in through the additional parameter (option), provided 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 are subject to the exchange's API documentation.
Not all exchanges support modifying condition orders: calling it on an unsupported exchange reports an error and returns a null value, and the original condition order must be canceled first and then recreated. Exchanges that do support modification may only support modifying some parameters (e.g. only certain contract types or a certain account mode). For unsupported exchanges, see the "Unsupported Exchanges" list on this page; for a comparison of support across exchanges, see the Capability Matrix; for specific restrictions, see each exchange's page.
Parameters can also be appended after the side parameter (legacy syntax): written as "side;{JSON对象}" or "side;key=value&key=value", for example "buy;{\"newTpTriggerPxType\":\"index\"}" or "buy;newTpTriggerPxType=index". The specific supported parameters depend on the exchange API.
The ConditionType of condition can take OCO, TP, or SL from ORDER_CONDITION_TYPE; ORDER_CONDITION_TYPE_GENERIC only appears in query results (for exchange-specific condition orders such as trailing stops) and cannot be used when creating or modifying condition orders; passing it reports an error and returns a null value. The trigger prices and execution prices required by the selected type must all be passed in and cannot be 0 (OCO requires all four, TP requires the two take-profit values, SL requires the two stop-loss values), otherwise an error is reported and a null value is returned; an execution price of -1 means a market order is executed once triggered.
Only these exchanges support this function: Binance, Bitfinex, Futures_Bitfinex, Bitget, Futures_Bitget, Bybit, Futures_Bybit, Crypto, Futures_Crypto, DeepCoin, Futures_DeepCoin, Futures_Deribit, Futures_GateIO, HitBTC, Kraken, Futures_Kraken, OKEX, Futures_OKCoin, Futures_WEEX, WOO, Futures_WOO, Futures_Hyperliquid, Futures_Lighter, Futures_Aevo, Futures_WOOFi. On every other exchange the call fails with an error and returns null; for all exchanges see Capability Matrix.