Skip to main content
An AI agent trades on OCX exactly the way a human client does: it reads market data, forms a view, places and cancels orders, watches its fills, and manages risk. There is no separate “agent API” — your agent speaks the same public REST and streaming surface, and authenticates headlessly with an API key instead of a browser session.
Everything an agent needs is public and documented. Market data is open, the order lifecycle is a handful of JSON endpoints, and execution updates arrive on a single Server-Sent Events stream. If you can write an HTTP client, you can write an OCX agent.

The agent loop

Every OCX agent, from a simple signal follower to a full market-making bot, reduces to the same cycle. Keep it tight and idempotent.
1

Read

Pull instruments, order books, stats, and candles — or subscribe to the live stream — to build your current view of the market.
2

Decide

Turn that view into an intent: an order to place, a quote ladder to refresh, or a position to reduce.
3

Act

Preview to size safely, then place or cancel. Use a clientOrderId so retries never double-submit.
4

Monitor

Consume the real-time stream to detect fills and position changes the instant they happen.
5

Manage risk

Track margin headroom, de-risk proactively, and wire cancel-all to your kill switch.

What your agent talks to

Market data (public)

Instruments, order books, 24h stats, fee tiers, and candles. No credentials required — sending your key is harmless but optional.

Trading (API key)

Preview, place, and cancel orders; refresh multi-level quote ladders in one atomic call; flatten positions.

Real-time stream (SSE)

One connection per market delivers the order book, your fills, and your position updates as they occur.

Account reads

Positions, open orders, trades, and balances — for reconciliation and risk checks between stream events.

Programmatic authentication

A human owner signs in once with Sign-In With Ethereum (SIWE), then provisions a scoped, IP-pinned, expiring API key for the agent. The agent sends that key as an x-api-key header on every request and never touches a wallet again.
POST {API_BASE}/perps/me/api-keys
Content-Type: application/json

{ "name": "signal-agent", "scope": "trade", "allowedIps": ["203.0.113.7"], "expiresInDays": 90 }
 { "id": "01H…", "secret": "ocx_sk_…", "message": "Copy this secret now — it will not be shown again." }
The secret is returned once and never again. Store it in a secret manager, never in source or logs. If it leaks, revoke the key immediately with DELETE {API_BASE}/perps/me/api-keys/{id}.

Scopes — grant least privilege

read

Market data plus your own account reads. Give this to research, monitoring, or signal-only agents that never trade.

trade

Everything read can do, plus order and quote actions. Reserve this for agents that actually execute.
Keys record their last-used time and IP for audit, and a key can never create or revoke another key — key management stays session-only.
Today the gateway accepts API keys on the high-throughput programmatic paths: order preview, bulk quotes, and cancel-all. The single-order place/cancel-by-id endpoints and the real-time stream run under a signed-in session. Agents that need discrete headless order placement should use the bulk-quote path or run under a session token. This coverage is expanding — check the current gateway policy for your integration.

Pricing your agent should understand

Your agent consumes prices and marks; it does not recompute the exchange’s internals. Treat the following as inputs to your strategy.
Perpetuals track an underlying index. Funding is exchanged periodically based on the gap between the perp’s mark and its index (plus a carry term), which nudges the perp price toward the underlying. Read the current funding context from /perps/market-stats, and fund your account to hold positions through funding periods.
A dated future is priced off spot plus a cost-of-carry term to expiry, so it trades at a premium or discount to spot (contango or backwardation). See the Futures methodology for the concept.
Option mark, iv, and delta on the board are OCX reference marks computed from a fitted volatility surface — published for reference and risk. The tradable prices are always the order book. See the Options methodology.

Risk is enforced server-side

OCX runs portfolio margin on the exchange side: every order passes a margin gate before acceptance. A rejected order returns an insufficient-margin error — handle it, don’t retry blindly. Positions that breach maintenance margin are liquidated by the exchange, with an insurance fund backstopping bad debt. Your agent should track its own margin headroom from balances and positions and de-risk before it gets there.
Build three safety reflexes into every agent from day one: use reduceOnly for exit-only orders, wire cancel-all to a single kill switch, and back off on 429 rate-limit responses. Respect the X-RateLimit-* headers.

Next step

Build an agent

A concrete walkthrough: authenticate, pull market data, size an order, submit it, monitor fills on the stream, and manage risk — with code.