Subscribe to the positions channel to receive pulsed position updates for all symbols.
Messages are pushed every 1 second.
1) Authenticate
{ "type": "auth", "params": { "api_key": "YOUR_API_KEY" } }
2) Subscribe
{ "type": "subscribe", "params": { "channels": ["positions"] } }
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):
send(ws, {"type": "auth", "params": {"api_key": API_KEY}})
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()
Example Responses
{ "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
}
}
Position updates are pulsed every second.