Messages are pushed every 1 second.
1) Authenticate
2) Subscribe
Sample Code
Example Responses
Position updates are pulsed every 10 seconds.
{
"type": "auth",
"params": {
"hmac": {
"public_key": "qfex_pub_xxxxx",
"nonce": "c0ffee...",
"unix_ts": 1760545414,
"signature": "5f2e..."
}
}
}
{ "type": "subscribe", "params": { "channels": ["positions"] } }
# Python (websocket-client)
import json, websocket
API_KEY = "YOUR_API_KEY"
def send(ws, obj): ws.send(json.dumps(obj))
def on_open(ws):
# 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..." }}})
send(ws, {"type": "subscribe", "params": {"channels": ["positions"]}})
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()
{ "subscribed": "positions" }
{
"position_response": {
"id": "c003ad60-ded4-401b-9b4c-e255a53d32ea",
"symbol": "AAPL-USD",
"position": 0.0,
"margin_alloc": 0.0,
"realised_pnl": 0.0,
"unrealised_pnl": 0.0,
"net_funding": 0.0,
"open_orders": 0.0,
"open_quantity": 0.0,
"leverage": 20.0,
"initial_margin": 0.05,
"maintenance_margin": 0.03333333333333333,
"average_price": 0.0
}
}