exchange.CancelOrder
The exchange.CancelOrder() function is used to cancel an order. The Id attribute of the FMZ platform's order Order structure consists of the exchange product code and the exchange's original order ID, separated by an English comma. For example, the Id attribute format for an order of the spot trading pair ETH_USDT on the OKX exchange is: ETH-USDT,1547130415509278720.
When calling the exchange.CancelOrder() function to cancel an order, the orderId parameter passed in should be consistent with the Id attribute of the order Order structure.
exchange.CancelOrder(orderId)
exchange.CancelOrder(orderId, ...args)Examples
-
Cancel an order.
javascriptfunction main(){ var id = exchange.Sell(99999, 1) exchange.CancelOrder(id) }pythondef main(): id = exchange.Sell(99999, 1) exchange.CancelOrder(id)c++void main() { auto id = exchange.Sell(99999, 1); exchange.CancelOrder(id); } -
In FMZ's API functions that can generate log output, such as
Log(),exchange.Buy(),exchange.CancelOrder(), etc., additional output parameters can be appended after the required parameters. For example:exchange.CancelOrder(orders[i].Id, orders[i]), this way when canceling the order with Idorders[i].Id, it will also output the order information, i.e., theOrderstructureorders[i].javascriptfunction main() { if (exchange.GetName().includes("Futures_")) { Log("Set contract to: perpetual swap, set direction to: open long.") exchange.SetContractType("swap") exchange.SetDirection("buy") } var ticker = exchange.GetTicker() exchange.Buy(ticker.Last * 0.5, 0.1) var orders = exchange.GetOrders() for (var i = 0 ; i < orders.length ; i++) { exchange.CancelOrder(orders[i].Id, "Canceled order:", orders[i]) Sleep(500) } }pythondef main(): if exchange.GetName().find("Futures_") != -1: Log("Set contract to: perpetual swap, set direction to: open long.") exchange.SetContractType("swap") exchange.SetDirection("buy") ticker = exchange.GetTicker() exchange.Buy(ticker["Last"] * 0.5, 0.1) orders = exchange.GetOrders() for i in range(len(orders)): exchange.CancelOrder(orders[i]["Id"], "Canceled order:", orders[i]) Sleep(500)c++void main() { if (exchange.GetName().find("Futures_") != std::string::npos) { Log("Set contract to: perpetual swap, set direction to: open long."); exchange.SetContractType("swap"); exchange.SetDirection("buy"); } auto ticker = exchange.GetTicker(); exchange.Buy(ticker.Last * 0.5, 0.1); auto orders = exchange.GetOrders(); for (int i = 0 ; i < orders.size() ; i++) { exchange.CancelOrder(orders[i].Id, "Canceled order:", orders[i]); Sleep(500); } }
Returns
| Type | Description |
bool | The |
Arguments
| Name | Type | Required | Description |
orderId | string | Yes | The |
arg | string / number / bool / object / array / any (any type supported by the platform) | No | Extended parameters that can output additional information to this cancel order log. Multiple |
See Also
Remarks
If using an older version of the docker, the orderId parameter of the exchange.CancelOrder() function may differ from the orderId described in the current documentation.