cancel_all_orders message.
Example Request
{
"type": "cancel_all_orders",
"params": {
"symbol": "AAPL-USD"
}
}
Sample Code
# Python (websocket-client)
import json, websocket
API_KEY = "YOUR_API_KEY"
def send(ws, obj): ws.send(json.dumps(obj))
def on_open(ws):
# Authenticate
# https://docs.qfex.com/websocket/channels/trade/authenticate#how-it-works
send(ws, {"type": "auth", "params": { "hmac": { "public_key": "qfex_pub_xxxxx", "nonce": "c0ffee...", "unix_ts": 1760545414, "signature": "5f2e..." }}})
# Cancel all orders
send(ws, {"type": "cancel_all_orders", "params": {}})
ws = websocket.WebSocketApp(
"wss://trade.qfex.com?api_key=YOUR_API_KEY",
on_open=on_open,
on_message=lambda _, m: print("Message:", m)
)
ws.run_forever()
// Node.js (ws)
import WebSocket from "ws";
const ws = new WebSocket("wss://trade.qfex.com?api_key=YOUR_API_KEY");
const API_KEY = "YOUR_API_KEY";
ws.on("open", () => {
// Authenticate
ws.send(JSON.stringify({ type: "auth", params: { api_key: API_KEY } }));
// Cancel all orders
ws.send(JSON.stringify({ type: "cancel_all_orders", params: {} }));
});
ws.on("message", (msg) => console.log("Message:", msg.toString()));
// Go (gorilla/websocket)
package main
import (
"log"
"github.com/gorilla/websocket"
)
func mustWriteJSON(c *websocket.Conn, v any) {
if err := c.WriteJSON(v); err != nil { log.Fatal("write:", err) }
}
func main() {
c, _, err := websocket.DefaultDialer.Dial("wss://trade.qfex.com?api_key=YOUR_API_KEY", nil)
if err != nil { log.Fatal("dial:", err) }
defer c.Close()
// Authenticate
mustWriteJSON(c, map[string]any{
"type": "auth",
"params": map[string]any{"hmac": map[string]any{"public_key": "qfex_pub_xxxxx", "nonce": "c0ffee...", "unix_ts": 1760545414, "signature": "5f2e..."}}
})
// Cancel all orders
mustWriteJSON(c, map[string]any{
"type": "cancel_all_orders",
"params": map[string]any{},
})
}
// Java (OkHttp WebSocket)
import java.util.concurrent.TimeUnit;
import okhttp3.*;
public class CancelAllOrdersWs {
public static void main(String[] args) {
OkHttpClient client = new OkHttpClient.Builder()
.pingInterval(20, TimeUnit.SECONDS).build();
Request req = new Request.Builder()
.url("wss://trade.qfex.com?api_key=YOUR_API_KEY").build();
WebSocketListener li = new WebSocketListener() {
@Override public void onOpen(WebSocket ws, Response r) {
// Authenticate
ws.send("{\"type\": \"auth\", \"params\": { \"hmac\": { \"public_key\": \"qfex_pub_xxxxx\", \"nonce\": \"c0ffee...\..\", \"unix_ts\": 1760545414, \"signature\": \"5f2e...\" }}}");
// Cancel all orders
ws.send("{\"type\":\"cancel_all_orders\",\"params\":{}}");
}
@Override public void onMessage(WebSocket ws, String text) {
System.out.println(text);
}
};
client.newWebSocket(req, li);
try { Thread.sleep(Long.MAX_VALUE); } catch (InterruptedException ignored) {}
}
}
Example Response
Every cancelled order will generate an order_response with statusCANCELLED.
{
"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
}
}
This cancels all open orders across all symbols for the authenticated
account, unless a
symbol is specified. If you only want to cancel specific
orders by ID, use the Cancel Order
endpoint instead.