Cancel order

This page will help you get started with sending order cancel requests through websocket connection

Channel: orders

Before cancelling orders on this channel, authentication is required.

Notes:

  • request_id: an optional string that the server will send back to the client in error responses.
  • Server only sends error message if the order cannot be canceled (order is "done" or does exists)
  • Server does not send a successful response
  • Instead, client must subscribe (sub) to orders channel to see if the order is "cancel_requested" or not.
    • All clients subscribe to this channel will see the created order message.
  • Client might send many cancel messages to create multiple orders, but the ordering of results are not guarantee.
  • Client might resend cancel message of the same order.
  • "cancel requested" does not guarantee order is canceled before matching. See Cancel Order V2 page

// Request
{
  "op": "cancel_order",
  "request_id": "your-unique-id-here",  // optional, should be less than 36 characters (enough for an uuid
  "channel": "orders",
  "data": { // you should only submit one and only one of these field: id, nonce, client_order_id
    "order_id": "a2b876b5-e0fe-4a44-bdca-aec5f5a18350",
    "nonce": "1740589329415243076", // this nonce can be used to detect successful order creatation
    "client_order_id": "your_client_order_id"
  }
}
// example of order cancel message 
// note that this response ONLY be sent when you already "sub" to orders channel before
{
  "channel": "orders",
  "type": "update",
  "data": [
    {
      "avg_price": "0",
      "cancel_reason": "",
      "cancel_reject_reason": "",
      "cancel_requested": true, // "true" indicate the request is success
      "cancel_requested_at": "1740899555396360000", // this field indicates successful request also
      "client_order_id": "",
      "created_at_ts": "1740589955539636000",
      "expired_at": "0",
      "filled_fees": "0",
      "filled_size": "0",
      "id": "4838b931-ddb7-4b8d-be22-bbe2f5b9935a",
      "initial_margin": "6.0064766903749975",
      "is_liquidation": false,
      "last_trades": [],
      "liquidation_fee_rate": "0",
      "maker_fee_rate": "0.0002",
      "nonce": "1740589955129439587",
      "order_stop_type": "STOP_NONE",
      "post_only": false,
      "price": "2399.2",
      "product_id": "ETH-PERP",
      "reduce_only": false,
      "reject_reason": "",
      "scheduled_at": "0",
      "sender": "0xa01f2319baf9e8a344486ebafa96fb3c9f5bda05",
      "side": "BUY",
      "size": "0.05",
      "status": "PENDING",
      "stop_price": "0",
      "stop_price_option": "NONE",
      "stp": "CANCEL_TAKER",
      "taker_fee_rate": "0.0004",
      "time_in_force": "GTC",
      "type": "LIMIT",
      "updated_at": "1740589955539636000"
    }
  ],
  "timestamp": "1740589955539636000"
}
// return when any error happens
{
  "channel": "orders",
  "type": "error",
  "message": "not authenticated",
  "code": 401, // same code with rest api
  "request_id": "your-unique-id-here",
  "payload": {}, // payload is echo back to client for detect the failed order, or client can use request_id
  "nonce": "1740589329415243076"
  }
}