User Data WebSocket Stream
Private WebSocket stream for real-time positions, open orders, and account balances on GaiaEx. Requires API key authentication.
SKILL.mdDrop-in Claude Code skill with HMAC-SHA256 signing, /fapi/v1 & /fapi/v2 schemas, and secret-redaction guardrails.
AGENTS.mdDrop-in repository AGENTS.md for OpenAI Codex CLI — tick-size rules, rate-limit budgets, and self-custody boundaries.
AGY.mdGoogle Antigravity (agy) & Gemini agent spec with verified async Python WebSocket + REST execution templates.
llms.txtSingle-URL machine-readable index of all GaiaEx documentation pages, OpenAPI 3.0 schema, and Postman collection.
https://openapi.gaiaex.com/fapi/v1/listenKeyHMACOverview
GaiaEx supports the GaiaEx Unified Futures User Data Stream lifecycle via /fapi/v1/listenKey alongside real-time WebSocket streaming for account balances, positions, and orders.
- REST ListenKey Base URL:
https://openapi.gaiaex.com - WebSocket Stream URL:
wss://openapi.gaiaex.com/ws/{listenKey} - Authentication: Pass your API key in the
X-MBX-APIKEYheader when calling/fapi/v1/listenKey. No query signature is required forlistenKeyendpoints.
https://openapi.gaiaex.com/fapi/v1/listenKeyHMACStart User Data Stream (USER_STREAM)
Start a new user data stream and obtain a listenKey for WebSocket subscription. Requires the X-MBX-APIKEY header.
Headers:
| Header | Required | Description |
|---|---|---|
X-MBX-APIKEY | YES | Your GaiaEx API key |
Parameters: None
Example Request:
curl -X POST "https://openapi.gaiaex.com/fapi/v1/listenKey" \
-H "X-MBX-APIKEY: your_api_key_here"Response:
{
"listenKey": "pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1"
}https://openapi.gaiaex.com/fapi/v1/listenKeyHMACKeepalive User Data Stream (USER_STREAM)
Keepalive a user data stream to prevent a time out. Recommended to send a ping about every 30 minutes.
Headers:
| Header | Required | Description |
|---|---|---|
X-MBX-APIKEY | YES | Your GaiaEx API key |
Parameters: None
Example Request:
curl -X PUT "https://openapi.gaiaex.com/fapi/v1/listenKey" \
-H "X-MBX-APIKEY: your_api_key_here"Response:
{
"listenKey": "pqia91ma19a5s61cv6a81va65sdf19v8a65a1a5s61cv6a81va65sdf19v8a65a1"
}https://openapi.gaiaex.com/fapi/v1/listenKeyHMACClose User Data Stream (USER_STREAM)
Close out a user data stream and invalidate the listenKey.
Headers:
| Header | Required | Description |
|---|---|---|
X-MBX-APIKEY | YES | Your GaiaEx API key |
Parameters: None
Example Request:
curl -X DELETE "https://openapi.gaiaex.com/fapi/v1/listenKey" \
-H "X-MBX-APIKEY: your_api_key_here"Response:
{}https://openapi.gaiaex.com/fapi/v1/listenKeyHMACWebSocket User Stream Subscription
Once you obtain a listenKey from POST /fapi/v1/listenKey, open a WebSocket connection to wss://openapi.gaiaex.com/ws/{listenKey} to receive real-time account, position, and order execution events.
Python Example
import asyncio
import json
import os
import requests
import websockets
API_KEY = os.environ["GAIAEX_API_KEY"]
REST_BASE = "https://openapi.gaiaex.com"
WS_BASE = "wss://openapi.gaiaex.com"
def get_listen_key() -> str:
resp = requests.post(
f"{REST_BASE}/fapi/v1/listenKey",
headers={"X-MBX-APIKEY": API_KEY},
timeout=10,
)
resp.raise_for_status()
return resp.json()["listenKey"]
async def stream_user_data():
listen_key = get_listen_key()
uri = f"{WS_BASE}/ws/{listen_key}"
async with websockets.connect(uri) as ws:
async for raw_msg in ws:
event = json.loads(raw_msg)
event_type = event.get("e") or event.get("type")
print(f"Event [{event_type}]:", event)
asyncio.run(stream_user_data())Account & Position Update Event (ACCOUNT_UPDATE)
Pushed whenever account balances or positions change.
{
"e": "ACCOUNT_UPDATE",
"E": 1743508800000,
"T": 1743508800000,
"a": {
"m": "ORDER",
"B": [
{
"a": "USDC",
"wb": "1000.00000000",
"cw": "1000.00000000",
"bc": "0"
}
],
"P": [
{
"s": "ETHUSDC",
"pa": "0.1",
"ep": "3500.00",
"cr": "0.00",
"up": "12.50",
"mt": "cross",
"iw": "0",
"ps": "BOTH"
}
]
}
}Order Trade Update Event (ORDER_TRADE_UPDATE)
Pushed whenever an order is created, modified, canceled, or filled.
{
"e": "ORDER_TRADE_UPDATE",
"E": 1743508800000,
"T": 1743508800000,
"o": {
"s": "ETHUSDC",
"c": "my_order_id_1",
"S": "BUY",
"o": "LIMIT",
"f": "GTC",
"q": "0.1",
"p": "3500.00",
"ap": "0.00000",
"sp": "0",
"x": "NEW",
"X": "NEW",
"i": 987654321,
"l": "0",
"z": "0",
"L": "0",
"T": 1743508800000,
"t": 0,
"R": false,
"ps": "BOTH"
}
}Ping / Keepalive
Standard WebSocket ping/pong frames are supported automatically, or you can send text "ping" and receive "pong". Remember to send PUT /fapi/v1/listenKey every 30 minutes to keep the listenKey active.