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

Cancels 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.

    javascript
    function main(){ var id = exchange.Sell(99999, 1) if (!id) return exchange.CancelOrder(id) }
    python
    def main(): id = exchange.Sell(99999, 1) if not id: return exchange.CancelOrder(id)
    rust
    fn main() { let Ok(id) = exchange.Sell(99999, 1) else { return }; let _ = 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 Id orders[i].Id, additionally output the information of that order, i.e. the Order structure orders[i].

    javascript
    function 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) } }
    python
    def 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)
    rust
    fn 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); } }

Returns

TypeDescription

bool / null value

The exchange.CancelOrder() function returning a truthy value (e.g. true) indicates that the order-cancellation request was sent successfully, while a null value is returned when the order-cancellation request fails to be sent. The return value only represents whether the request was sent successfully or not; to determine whether the exchange has actually canceled the order, you can call exchange.GetOrders() to check.

Arguments

NameTypeRequiredDescription

orderId

string

Yes

Order to be canceled.

arg

string / number / bool / object / array / any

No

An extension parameter used to output accompanying information into this order-cancellation log; multiple arg parameters can be passed in.

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.

Exchanges that do not support this function: OKX_DEX, Web3. The call fails with an error and returns null; for all exchanges see Capability Matrix.