AI Agent Integration Guide
Integrate AI trading agents with GaiaEx: no-KYC API keys, scoped permissions, HMAC authentication, and code examples for autonomous trading.
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.
AI Agent Integration
GaiaEx is designed as a bounded execution layer for AI trading agents with GaiaEx Unified Futures (/fapi/v1 & /fapi/v2) compatibility. You give the agent a trade-scoped API key, it authenticates with standard X-MBX-APIKEY + query/form HMAC-SHA256 signatures, and your wallet address is automatically resolved server-side from the API key. Funds stay under your self-custody at all times — the agent never has the ability to move money on or off the platform.
WHY GaiaEx FOR AI AGENTS
- Bounded risk — the worst an agent can do is trade badly within your deposited balance. It cannot withdraw, deposit, transfer, or swap on-chain.
- GaiaEx Unified Futures API standard — any LLM agent, LangChain/MCP tool, or CCXT skill trained on standard
/fapi/v1/*and/fapi/v2/*schemas works out of the box with zero schema rewrites. - Scoped permissions —
read-only agents for monitoring and analytics;read + tradeagents for execution. - 167+ markets in one API — crypto perps (133 USDC-margined + 34 USDT-margined), RWA (stocks, commodities, forex), and venture tokens.
- WebSocket streaming — real-time market depth, klines, and user data streams via
POST /fapi/v1/listenKey.
Agent Scope — What It Can and Cannot Do
API-key-authenticated agents operate strictly within a trading and read scope. The table below is the complete, accurate picture — share it with the agent's system prompt so it understands its own capabilities.
| Agent can | Agent cannot |
|---|---|
Place, cancel, and modify orders (POST/DELETE/PUT /fapi/v1/order) | Deposit USDC/USDT into the account |
| Close positions and set TP/SL orders | Withdraw funds off the platform |
Change leverage (POST /fapi/v1/leverage) and margin mode (POST /fapi/v1/marginType) | Transfer assets on-chain (sendAsset, dex-transfer) |
Read balances (GET /fapi/v2/balance), positions (GET /fapi/v2/positionRisk), and fills (GET /fapi/v1/userTrades) | Execute wallet swaps |
Subscribe to public and private WebSocket streams (POST /fapi/v1/listenKey) | Register or authenticate passkeys |
Query market data (GET /fapi/v1/exchangeInfo, /fapi/v1/depth, /fapi/v1/klines, /fapi/v1/ticker/24hr) | Complete the account handshake |
Query open orders (GET /fapi/v1/openOrders) and order history (GET /fapi/v1/allOrders) | Create, modify, or delete API keys |
FUNDING IS A MANUAL STEP
The user must fund the account in the GaiaEx mobile app before the agent runs. If the account runs out of margin mid-strategy, the agent will receive -2019 MARGIN_NOT_SUFFICIENCE on new orders — it cannot top up on its own. When the user is ready to pull funds out, they do so in the mobile app, not through the agent.
Agent Authentication & Execution Flow
The recommended flow for AI agent authentication using the GaiaEx Unified Futures standard:
- Human creates API key in the GaiaEx mobile app → sets permissions to
["read", "trade"]and adds an IP whitelist for the agent server. - Store credentials (
GAIAEX_API_KEYandGAIAEX_API_SECRET) in a secrets manager or environment variables on the agent's server (see Security Best Practices). No wallet address parameter is needed — GaiaEx resolves the wallet directly fromX-MBX-APIKEY. - Agent signs requests using standard query-string
HMAC-SHA256and sends theX-MBX-APIKEYheader. - Agent trades autonomously via
/fapi/v1/*and/fapi/v2/*endpoints.
import hmac, hashlib, time, os, urllib.parse, requests
API_KEY = os.environ["GAIAEX_API_KEY"]
API_SECRET = os.environ["GAIAEX_API_SECRET"]
BASE = "https://openapi.gaiaex.com"
def fapi_request(method: str, path: str, params: dict | None = None):
p = dict(params or {})
p["timestamp"] = int(time.time() * 1000)
query = urllib.parse.urlencode(p)
signature = hmac.new(API_SECRET.encode(), query.encode(), hashlib.sha256).hexdigest()
url = f"{BASE}{path}?{query}&signature={signature}"
return requests.request(method, url, headers={"X-MBX-APIKEY": API_KEY}).json()
# 1. Verify connectivity & server time
assert requests.get(f"{BASE}/fapi/v1/ping").status_code == 200
# 2. Check account balances (GET /fapi/v2/balance) and open positions (GET /fapi/v2/positionRisk)
balances = fapi_request("GET", "/fapi/v2/balance")
positions = fapi_request("GET", "/fapi/v2/positionRisk", {"symbol": "ETHUSDC"})
usdc_avail = next((float(b["availableBalance"]) for b in balances if b["asset"] == "USDC"), 0.0)
# 3. Place a limit order (POST /fapi/v1/order)
if usdc_avail > 100:
order = fapi_request("POST", "/fapi/v1/order", {
"symbol": "ETHUSDC",
"side": "BUY",
"type": "LIMIT",
"quantity": "0.1",
"price": "3500.00",
"timeInForce": "GTC",
})
print("Placed order:", order)SECURITY
Always configure IP whitelisting for agent API keys. If the agent server is compromised, IP restrictions prevent the key from being used from unauthorized hosts.
Real-Time Data for AI Agents
For low-latency AI agents, combine WebSocket market streams with a user data stream initialized via POST /fapi/v1/listenKey instead of polling REST endpoints.
import asyncio
import websockets
import json
async def ai_agent():
uri = "wss://openapi.gaiaex.com/ws/market/ETH"
async with websockets.connect(uri) as ws:
count = 0
async for raw in ws:
msg = json.loads(raw)
if msg.get("type") == "orderbook":
bids = msg.get("bids", [])
best_bid = bids[0][0] if bids else "N/A"
print(f"ETH best bid: {best_bid}")
count += 1
if count >= 5:
break
asyncio.run(ai_agent())PRODUCTION TIP
For production AI agents, run the market data stream and the user data stream concurrently using asyncio.gather. This gives your agent real-time orderbook updates and instant position/fill notifications in a single event loop.