# Python (websocket-client)
# pip install websocket-client
import json
import websocket
API_KEY = "YOUR_API_KEY"
def send(ws, obj):
ws.send(json.dumps(obj))
def on_open(ws):
# 1) 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..." }}})
# 2) Sub to order responses
# https://docs.qfex.com/websocket/channels/trade/order
send(ws, {"type": "subscribe", "params": {"channels": ["order_responses"]}})
# 3) Add order
send(ws, {
"type": "add_order",
"params": {
"symbol": "AAPL-USD",
"side": "BUY",
"order_type": "LIMIT",
"order_time_in_force": "GTC",
"quantity": 1,
"price": 200,
"take_profit": 0, # Optional
"stop_loss": 0 # Optional
}
})
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()