# 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()