Skip to main content
Mark a WebSocket session with cancel-on-disconnect to make sure the trade engine closes every open order for the account (not just orders placed via this connection) if the connection drops unexpectedly. The flag is scoped to a single connection, so you need to opt in again whenever you reconnect. Send a cancel_on_disconnect message with cancel_on_disconnect set to true immediately after authenticating on any connection you want protected.

Example Request

{
  "type": "cancel_on_disconnect",
  "params": { "cancel_on_disconnect": true }
}

Sample Code

# Python (websocket-client)
import json
import websocket

API_KEY = "YOUR_API_KEY"


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


def on_open(ws):
    # Authenticate
    send(ws, {"type": "auth", "params": {"api_key": API_KEY}})
    # Enable cancel-on-disconnect for this connection
    send(ws, {"type": "cancel_on_disconnect", "params": {"cancel_on_disconnect": True}})


ws = websocket.WebSocketApp(
    "wss://trade.qfex.com?api_key=YOUR_API_KEY",
    on_open=on_open,
    on_message=lambda _, message: print("Message:", message),
)
ws.run_forever()

Example Response

Cancelling with this flag immediately returns an order_response event for each order with status CANCELLED.
{
  "order_response": {
    "order_id": "5b309929-206f-40ec-804d-cbe46e81afc1",
    "symbol": "AAPL-USD",
    "status": "CANCELLED",
    "quantity": 1.0,
    "price": 200.0,
    "side": "BUY",
    "type": "LIMIT",
    "time_in_force": "GTC",
    "user_id": "0020ce8e-eaee-480e-8d7f-b9241d756ee5",
    "client_order_id": "my-client-oid",
    "quantity_remaining": 1.0,
    "trade_id": null
  }
}
Enabling cancel-on-disconnect cancels all open orders across all symbols for the authenticated account. If you only want to cancel specific orders, use the Cancel Order endpoint instead.