Type/to search
Built-in Functions
Global
Version
Sleep
IsVirtual
Mail
Mail_Go
SetErrorFilter
GetPid
GetLastError
GetCommand
GetMeta
Dial
HttpQuery
HttpQuery_Go
Encode
UnixNano
Unix
GetOS
MD5
DBExec
UUID
EventLoop
__Serve
_G
_D
_N
_C
_Cross
JSON.parse
JSON.stringify
SetChannelData
GetChannelData
Log
Market
Trade
Account
Futures
NetSettings
Threads
threading
Thread
getThread
mainThread
currentThread
Lock
Condition
Event
Dict
pending
Thread
ThreadLock
ThreadEvent
ThreadCondition
ThreadDict
Web3
TA
Talib
talib.CDL2CROWS
talib.CDL3BLACKCROWS
talib.CDL3INSIDE
talib.CDL3LINESTRIKE
talib.CDL3OUTSIDE
talib.CDL3STARSINSOUTH
talib.CDL3WHITESOLDIERS
talib.CDLABANDONEDBABY
talib.CDLADVANCEBLOCK
talib.CDLBELTHOLD
talib.CDLBREAKAWAY
talib.CDLCLOSINGMARUBOZU
talib.CDLCONCEALBABYSWALL
talib.CDLCOUNTERATTACK
talib.CDLDARKCLOUDCOVER
talib.CDLDOJI
talib.CDLDOJISTAR
talib.CDLDRAGONFLYDOJI
talib.CDLENGULFING
talib.CDLEVENINGDOJISTAR
talib.CDLEVENINGSTAR
talib.CDLGAPSIDESIDEWHITE
talib.CDLGRAVESTONEDOJI
talib.CDLHAMMER
talib.CDLHANGINGMAN
talib.CDLHARAMI
talib.CDLHARAMICROSS
talib.CDLHIGHWAVE
talib.CDLHIKKAKE
talib.CDLHIKKAKEMOD
talib.CDLHOMINGPIGEON
talib.CDLIDENTICAL3CROWS
talib.CDLINNECK
talib.CDLINVERTEDHAMMER
talib.CDLKICKING
talib.CDLKICKINGBYLENGTH
talib.CDLLADDERBOTTOM
talib.CDLLONGLEGGEDDOJI
talib.CDLLONGLINE
talib.CDLMARUBOZU
talib.CDLMATCHINGLOW
talib.CDLMATHOLD
talib.CDLMORNINGDOJISTAR
talib.CDLMORNINGSTAR
talib.CDLONNECK
talib.CDLPIERCING
talib.CDLRICKSHAWMAN
talib.CDLRISEFALL3METHODS
talib.CDLSEPARATINGLINES
talib.CDLSHOOTINGSTAR
talib.CDLSHORTLINE
talib.CDLSPINNINGTOP
talib.CDLSTALLEDPATTERN
talib.CDLSTICKSANDWICH
talib.CDLTAKURI
talib.CDLTASUKIGAP
talib.CDLTHRUSTING
talib.CDLTRISTAR
talib.CDLUNIQUE3RIVER
talib.CDLUPSIDEGAP2CROWS
talib.CDLXSIDEGAP3METHODS
talib.AD
talib.ADOSC
talib.OBV
talib.ACOS
talib.ASIN
talib.ATAN
talib.CEIL
talib.COS
talib.COSH
talib.EXP
talib.FLOOR
talib.LN
talib.LOG10
talib.SIN
talib.SINH
talib.SQRT
talib.TAN
talib.TANH
talib.MAX
talib.MAXINDEX
talib.MIN
talib.MININDEX
talib.MINMAX
talib.MINMAXINDEX
talib.SUM
talib.HT_DCPERIOD
talib.HT_DCPHASE
talib.HT_PHASOR
talib.HT_SINE
talib.HT_TRENDMODE
talib.ATR
talib.NATR
talib.TRANGE
talib.BBANDS
talib.DEMA
talib.EMA
talib.HT_TRENDLINE
talib.KAMA
talib.MA
talib.MAMA
talib.MIDPOINT
talib.MIDPRICE
talib.SAR
talib.SAREXT
talib.SMA
talib.T3
talib.TEMA
talib.TRIMA
talib.WMA
talib.LINEARREG
talib.LINEARREG_ANGLE
talib.LINEARREG_INTERCEPT
talib.LINEARREG_SLOPE
talib.STDDEV
talib.TSF
talib.VAR
talib.ADX
talib.ADXR
talib.APO
talib.AROON
talib.AROONOSC
talib.BOP
talib.CCI
talib.CMO
talib.DX
talib.MACD
talib.MACDEXT
talib.MACDFIX
talib.MFI
talib.MINUS_DI
talib.MINUS_DM
talib.MOM
talib.PLUS_DI
talib.PLUS_DM
talib.PPO
talib.ROC
talib.ROCP
talib.ROCR
talib.ROCR100
talib.RSI
talib.STOCH
talib.STOCHF
talib.STOCHRSI
talib.TRIX
talib.ULTOSC
talib.WILLR
talib.AVGPRICE
talib.MEDPRICE
talib.TYPPRICE
talib.WCLPRICE
OS
Structures
Built-in Variables

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.

    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); }
    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.

    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 // 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) }
    python
    import 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)
    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 // 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

TypeDescription

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

NameTypeRequiredDescription

orderId

string

Yes

The orderId parameter is used to specify the ID of the original order to be modified. The order ID format is consistent with the order ID returned by the exchange.CreateOrder function, consisting of the exchange symbol code and the exchange's original order ID, separated by an English comma. For example: "ETH-USDT,1547130415509278720".

side

string

Yes

The side parameter is used to specify the order's trade direction.

For spot exchange objects, the available values for the side parameter are: buy, sell. Here, buy means buy and sell means sell.

For futures exchange objects, the available values for the side parameter are: buy, closebuy, sell, closesell. Here, buy means open long position, closebuy means close long position, sell means open short position, and closesell means close short position.

Supports additional parameters (option): Additional parameters can be passed via the side parameter, in the format "side;{JSON object}" or "side;key=value&key=value".

For example: "buy;{\"priceMatch\":\"QUEUE_20\"}" or "buy;priceMatch=QUEUE_20".

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 price parameter is used to set the new price of the order. When the price is -1, it means the price is not modified, or depending on the exchange API implementation, it may be converted to a market order.

amount

number

Yes

The amount parameter is used to set the new order quantity. When the quantity is -1, it means the quantity is not modified. Note that when the order is a spot market buy order, the order quantity represents the buy amount; for the market buy orders of certain spot exchanges, the order quantity is the amount of the trading currency.

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.