Subscribe to the balances channel to receive pulsed account balance updates.
Messages are pushed every 1 second.

1) Authenticate

Send this immediately after connecting to wss://trade.qfex.com?api_key=YOUR_API_KEY:
{ "type": "auth", "params": { "api_key": "YOUR_API_KEY" } }

2) Subscribe

{ "type": "subscribe", "params": { "channels": ["balances"] } }

Sample Code

# Python (websocket-client)
# pip install websocket-client
import json, websocket

API_KEY = "YOUR_API_KEY"

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

def on_open(ws):
    # 1) Authenticate
    send(ws, {"type": "auth", "params": {"api_key": API_KEY}})
    # 2) Subscribe to balances
    send(ws, {"type": "subscribe", "params": {"channels": ["balances"]}})

ws = websocket.WebSocketApp(
    "wss://trade.qfex.com?api_key=YOUR_API_KEY",
    on_open=on_open,
    on_message=lambda _, m: print("Message:", m),
    on_error=lambda _, e: print("Error:", e),
    on_close=lambda *_: print("Closed"),
)
ws.run_forever()

Example Responses

{ "subscribed": "balances" }
{
  "balance_response": {
    "id": "0020ce8e-eaee-480e-8d7f-b9241d756ee5",
    "user_id": "0020ce8e-eaee-480e-8d7f-b9241d756ee5",
    "deposit": 9990000000.0,
    "realised_pnl": 0.0,
    "order_margin": 0.0,
    "position_margin": 0.0,
    "unrealised_pnl": 0.0,
    "net_funding": 0.0,
    "available_balance": 9990000000.0
  }
}
Balance updates are pulsed every second.