Type/to search
Built-in Functions
Global
Log
Market
Trade
Account
Futures
Exchange
IO
Network
Storage
Threads
TA
Talib
OS
Structures
Built-in Variables and Constants
Conventions
Exchanges

Modifies the price and quantity of an existing regular order. You can also change other order attributes through extra parameters, if the exchange API supports it.

exchange.ModifyOrder(orderId, side, price, amount)
exchange.ModifyOrder(orderId, side, price, amount, options)

Examples

  • Modify the price and quantity of a regular order.

    javascript
    function 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) }
    python
    def 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)
    rust
    fn 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); }
  • Modifies an order's price match mode through the extra parameter (option).

    javascript
    function 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 (exchange-specific parameters are passed in through the last object parameter) var newId = exchange.ModifyOrder(id, "buy", -1, 2, {priceMatch: "QUEUE_20"}) 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) }
    python
    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 (exchange-specific parameters are passed in through the last object parameter) newId = exchange.ModifyOrder(id, "buy", -1, 2, {"priceMatch": "QUEUE_20"}) 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)
    rust
    fn 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 (in Rust, object parameters are passed in through the function with the WithOptions suffix) let opts = JSONParse(r#"{"priceMatch": "QUEUE_20"}"#).unwrap(); let newId = exchange.ModifyOrderWithOptions(&id, "buy", -1, 2, &opts).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); }

Returns

TypeDescription

string / null value

Returns the order ID if the modification succeeds, or a null value if it fails. The returned order ID may be the same as the original order ID or different, depending on the exchange API: some exchanges return a new order ID after the order is modified, while others keep the same order ID.

Arguments

NameTypeRequiredDescription

orderId

string

Yes

ID of the original order to modify. It uses the same format as the order ID returned by the exchange.CreateOrder function: the exchange symbol code and the exchange's original order ID, separated by a comma. For example: "ETH-USDT,1547130415509278720".

side

string

Yes

Trade direction. For spot: buy (buy) and sell (sell). For futures: buy (open long), sell (open short), closebuy (close long) and closesell (close short). You can append exchange-specific parameters. See the remarks for details.

price

number

Yes

New price of the order. Set it to -1 (or any other value less than or equal to 0) to keep the price unchanged.

amount

number

Yes

New order quantity. Set it to -1 (or any other value less than or equal to 0) to keep the quantity unchanged. You must change the price, the quantity or both. If you leave both unchanged, an error is reported and a null value is returned. Note: for a spot market buy order, the order quantity is the amount of quote currency to spend. On a few spot exchanges, the quantity of a market buy order is the number of coins to buy.

options

object

No

Exchange-specific parameters. The object's keys are passed to the exchange as they are, for example {"priceMatch":"QUEUE_20"}. An extra sub-object is expanded first. In Rust, pass them through exchange.ModifyOrderWithOptions().

See Also

Remarks

The order ID returned by the exchange.ModifyOrder() function depends on how the exchange API is implemented: some exchanges return an updated order ID, while others keep the original order ID. Use the returned order ID in later operations.

If -1 (or any value less than or equal to 0) is passed as the price or amount parameter of the exchange.ModifyOrder() function, that field is not sent to the exchange and stays unchanged. If neither field is changed, the function reports an error and returns a null value. Other parameters are not checked against the exchange's API rules and are sent directly to the exchange API.

Exchange-specific parameters (option) go in the last parameter, an object, and change other attributes of the order. For example, to change the price match mode: exchange.ModifyOrder(id, "buy", -1, 2, {priceMatch: "QUEUE_20"}). In Rust, use exchange.ModifyOrderWithOptions().

Whether a market order among regular orders can be modified depends on the exchange API. Some exchanges do not support modifying market orders.

When an order is modified, its other attributes (such as order type, position mode, account mode, leverage and time in force) usually keep the original order's settings. To change these attributes, pass them through the extra parameter (option), if the exchange API supports it.

For spot market buy orders, the order amount may be in quote currency (the amount to spend) rather than the number of coins.

Support for order modification varies by exchange. Some exchanges do not support modifying orders, or only allow some parameters to be changed. Check the exchange's API documentation before use.

Parameters can also be appended to the side parameter (legacy syntax), in the format "side;{JSON对象}" or "side;key=value&key=value", for example "buy;{\"priceMatch\":\"QUEUE_20\"}" or "buy;priceMatch=QUEUE_20". The supported parameters depend on the exchange API.

Only these exchanges support this function: Binance, Futures_Binance, Bitfinex, Futures_Bitfinex, Bitget, Futures_Bitget, Bybit, Futures_Bybit, Crypto, Futures_Crypto, Futures_DeepCoin, Futures_Deribit, GateIO, Futures_GateIO, HitBTC, Kraken, Futures_Kraken, KuCoin, Futures_MEXC, OKEX, Futures_OKCoin, Poloniex, Upbit, WOO, Futures_WOO, Hyperliquid, Futures_Hyperliquid, Futures_Lighter, Futures_Aevo, Futures_dYdX, Futures_Boros, Futures_WOOFi, Jupiter, Futures_Futu. On every other exchange the call fails with an error and returns null; for all exchanges see Capability Matrix.