exchange.CancelOrder
The exchange.CancelOrder() function is used to cancel an order. In the order Order structure of the FMZ platform, the property Id is composed of the exchange's symbol code and the exchange's original order Id, separated by an English comma. For example, for an order of the OKX exchange spot trading pair ETH_USDT, the format of its Id property is: ETH-USDT,1547130415509278720.
When calling the exchange.CancelOrder() function to cancel an order, the passed-in parameter orderId is consistent with the Id property 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)rustfn main() { let id = exchange.Sell(99999, 1).unwrap(); let _ = exchange.CancelOrder(&id); }c++void main() { auto id = exchange.Sell(99999, 1); exchange.CancelOrder(id); } -
Among FMZ's API functions, functions that can produce log output (such as
Log(),exchange.Buy(),exchange.CancelOrder(), etc.) can all be accompanied by some output parameters after the required parameters.For example:
exchange.CancelOrder(orders[i].Id, orders[i]), that is, when canceling the order with Idorders[i].Id, additionally output the information of that order, 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)rustfn main() { if exchange.GetName().contains("Futures_") { Log!("Set contract to: perpetual swap, set direction to: open long."); let _ = exchange.SetContractType("swap"); let _ = exchange.SetDirection("buy"); } let ticker = exchange.GetTicker(None).unwrap(); let _ = exchange.Buy(ticker.Last * 0.5, 0.1); let orders = exchange.GetOrders(None).unwrap(); for i in 0..orders.len() { // Rust does not support appending output parameters after the required parameters of CancelOrder; after canceling the order, call the Log! macro separately to output the accompanying information let _ = exchange.CancelOrder(&orders[i].Id); Log!("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 parameter |
arg | string / number / bool / object / array / any (any type supported by the platform) | No | An extension parameter used to output accompanying information into this order-cancellation log; multiple |
See Also
Remarks
If you are using an older version of the docker (hosting agent), the parameter orderId of the exchange.CancelOrder() function may differ from the orderId described in the current documentation.