Order cancellation is performed over WebSocket.
  • Endpoint: wss://trade.qfex.com?api_key=YOUR_API_KEY
  • Authenticate within 1 minute of connecting.

1) Authenticate

Send this immediately after you connect:
{ "type": "auth", "params": { "api_key": "YOUR_API_KEY" } }

2) Cancel Order

You can cancel by either order_id or client_order_id:
  • order_id — always a UUID v4 and unique. Cancels exactly one order.
  • client_order_idnot guaranteed unique. Cancels all orders for that symbol that share this client order id.
Use the cancel_order_id_type field to specify which one you’re sending: "order_id" or "client_order_id".

Cancel by order_id (single order)

{
  "type": "cancel_order",
  "params": {
    "order_id": "REPLACE_WITH_ORDER_UUID_V4",
    "symbol": "AAPL-USD",
    "cancel_order_id_type": "order_id"
  }
}

Cancel by client_order_id (may cancel multiple)

{
  "type": "cancel_order",
  "params": {
    "client_order_id": "my-client-oid-123",
    "symbol": "AAPL-USD",
    "cancel_order_id_type": "client_order_id"
  }
}

Parameters

FieldTypeRequiredDescription
order_idstringOptionalUUID v4 of the order to cancel. Required if cancel_order_id_type = "order_id". Cancels exactly one order.
client_order_idstringOptionalClient-specified ID to cancel orders. Required if cancel_order_id_type = "client_order_id". May cancel multiple orders.
symbolstringMarket symbol of the order(s) (e.g. AAPL-USD).
cancel_order_id_typeenumMust be "order_id" or "client_order_id". Tells the engine how to interpret the ID.
⚠️ Notes:
  • You must provide either order_id or client_order_id, depending on cancel_order_id_type.
  • order_id is always unique (UUID v4).
  • client_order_id is not guaranteed unique and may cancel multiple orders for the same symbol.
  • Responses will include OrderStatus codes, e.g. CANCELLED, NO_SUCH_ORDER, or REJECTED.

Sample Code

# Python (websocket-client)
# pip install websocket-client
import json
import websocket

API_KEY = "YOUR_API_KEY"
ORDER_ID = "REPLACE_WITH_ORDER_UUID_V4"          # for order_id flow
CLIENT_OID = "my-client-oid-123"                 # for client_order_id flow

def send(ws, obj):
    ws.send(json.dumps(obj))

def on_open(ws):
    # 1) Authenticate
    send(ws, {"type": "auth", "params": {"api_key": API_KEY}})

    # 2a) Cancel by order_id (exactly one order)
    send(ws, {
        "type": "cancel_order",
        "params": {
            "order_id": ORDER_ID,
            "symbol": "AAPL-USD",
            "cancel_order_id_type": "order_id"
        }
    })

    # 2b) Cancel by client_order_id (may cancel multiple)
    # send(ws, {
    #     "type": "cancel_order",
    #     "params": {
    #         "client_order_id": CLIENT_OID,
    #         "symbol": "AAPL-USD",
    #         "cancel_order_id_type": "client_order_id"
    #     }
    # })

ws = websocket.WebSocketApp(
    "wss://trade.qfex.com?api_key=YOUR_API_KEY",
    on_open=on_open,
    on_message=lambda _, m: print(m),
    on_error=lambda _, e: print("Error:", e),
    on_close=lambda *_: print("Closed"),
)
ws.run_forever()

Example Response

Placing an order returns ACK. Cancelling it returns the same structure but with status CANCELLED.
{
  "order_response": {
    "order_id": "5b309929-206f-40ec-804d-cbe46e81afc1",
    "symbol": "AAPL-USD",
    "status": "CANCELLED",
    "quantity": 1.0,
    "price": 200.0,
    "take_profit": 0.0,
    "stop_loss": 0.0,
    "side": "BUY",
    "type": "LIMIT",
    "time_in_force": "GFD",
    "user_id": "0020ce8e-eaee-480e-8d7f-b9241d756ee5",
    "client_order_id": "",
    "quantity_remaining": 1.0
  }
}