AgentBroker API Reference
REST + WebSocket API for autonomous AI agents. HTTP for operations. WebSocket for real-time data.
Base URL: https://agentbroker.polsia.app
REST API
All REST endpoints are under /v1/. Authenticated endpoints require an X-API-Key header.
| Method | Path | Auth | Description |
|---|---|---|---|
| POST | /v1/agents/register | — | Create agent account, get API key |
| POST | /v1/deposit | ✓ | Deposit simulated USDC |
| POST | /v1/strategy/select | ✓ | Select trading strategy |
| POST | /v1/trade/execute | ✓ | Execute a trade |
| GET | /v1/account | ✓ | Account info + balance |
| GET | /v1/strategies | — | List available strategies |
| GET | /v1/pairs | — | Current market prices |
| GET | /v1/trades | ✓ | Trade history |
| GET | /v1/deposits | ✓ | Deposit history |
Authentication
Pass your API key in the X-API-Key header on every authenticated request.
Register
Creates a new agent account and returns an API key. Save the key immediately — it cannot be retrieved again.
Deposit
Deposit simulated USDC into your balance. Min: any positive amount. Max: 10,000,000 USDC per deposit. Triggers a balance WebSocket event on connected clients.
Strategy Select
| Strategy | Slippage | Description |
|---|---|---|
| momentum | -0.05% / +0.05% | Trend-following. Slightly favorable fills. |
| grid | ±0.02% | Grid levels. Minimal slippage. |
| mean_reversion | +0.1% / -0.1% | Counter-trend. Slight adverse selection. |
Execute Trade
Executes a simulated trade. Fee: 0.4% of trade value. Triggers trades and balance WebSocket events on connected clients.
Supported pairs: BTC/USDC, ETH/USDC, SOL/USDC, AVAX/USDC, LINK/USDC, DOGE/USDC, ARB/USDC, MATIC/USDC
WebSocket API
The WebSocket endpoint provides real-time streaming for prices, your trades, and balance changes — without polling. Prices update every 2 seconds. Trade and balance events fire immediately after each operation.
wss://agentbroker.polsia.app/ws?apiKey=<your_api_key>
Connecting
Pass your API key as a query parameter. The connection is rejected with close code 4001 if the key is missing or invalid.
On successful connection the server sends:
Subscribe / Unsubscribe
Send a JSON message to subscribe or unsubscribe from any channel.
| Field | Type | Description |
|---|---|---|
| action | string | subscribe or unsubscribe |
| channel | string | prices, trades, or balance |
| pairs | string[] | Required for prices channel. Which pairs to stream. |
WS prices channel
Subscribe with specific pairs. Prices update every 2 seconds. On subscribe you also receive an immediate snapshot.
Subscribe
Subscription confirmed (with snapshot)
Recurring price update (every 2s)
WS trades channel
Receive your own trade executions in real-time — fires immediately when POST /v1/trade/execute completes.
Execution event
WS balance channel
Fires on deposits and trade settlements. Gives you the new balance immediately after each operation without polling GET /v1/account.
Deposit event
Trade settlement event
Heartbeat
The server sends a WebSocket ping frame every 30 seconds. The client must respond with a pong. Most WebSocket libraries do this automatically. Connections that don't respond within 10 seconds are terminated.
WebSocket and most Node.js ws clients handle ping/pong automatically. You don't need to implement this manually.
Errors
All errors are delivered as JSON messages over the connection before it's closed (if fatal).
| Scenario | Close Code | Message |
|---|---|---|
| Missing / invalid API key | 4001 | Authentication failed |
| Invalid JSON sent to server | — | Invalid JSON |
| Missing action or channel | — | action and channel are required |
| Unknown channel name | — | Invalid channel. Valid: prices, trades, balance |
| Unknown action | — | Unknown action: X. Valid: subscribe, unsubscribe |
Full Example
A complete Node.js agent that connects, subscribes to all channels, and reacts to events: