All traffic goes through the single OCX API gateway at one HTTPS base URL,
written below as
{API_BASE}. Prices and quantities are JSON strings
(fixed-decimal) — keep them as strings end to end to preserve precision.Step 1 — Provision an API key
A human owner signs in once with SIWE, then mints a scoped key for the agent. See Authentication for the SIWE flow; the key step is:Step 2 — Read the market
Market data needs no auth. Discover instruments, then read the book and stats for the market you want to trade.Step 3 — Size the order with a preview
Always dry-run before you commit.preview returns the notional, estimated fee,
your fee role and rolling-volume tier, and — critically — whether the order would
pass the server-side margin gate. It has no side effects.
Whether the order would pass the margin gate. If
false, read reason and
resize or fund — do not retry the same order.Collateral the order would lock. Compare against your free balance.
Estimated fee for this fill, with
feeBps and feeRole (maker/taker).Order notional in quote currency.
Step 4 — Submit the order
With an approved preview, place the order. Set aclientOrderId so a network
retry can never create a duplicate.
For multi-order strategies (grids, liquidity ladders), prefer
POST /perps/quotes/bulk with cancelAll: true — it atomically replaces your
whole ladder in one call and is fully API-key enabled. See the
Market maker quoting guide.Time in force
Time in force
gtc rests until filled or cancelled; ioc fills what it can immediately then
cancels the rest; fok fills fully or cancels entirely.postOnly / reduceOnly
postOnly / reduceOnly
postOnly rejects an order that would take liquidity (keeps you on the maker
side). reduceOnly prevents an order from ever increasing your position — use
it for exits.Protective orders
Protective orders
Attach
stopPrice, takeProfitPrice, or stopLossPrice for automated
conditional exits.Step 5 — Monitor fills over the stream
Open one Server-Sent Events connection per market. On connect you receive asnapshot (order book, recent trades, and your positions); after that,
delta events push incremental order-book changes, new trades, and position
upserts as they happen. A fill shows up as a trade plus a position delta — that’s
your signal to rebalance.
Step 6 — Manage risk and shut down cleanly
Risk is enforced server-side, but your agent still owns its own limits. Track margin headroom, de-risk proactively, and always have a kill path.The full loop
Provision
Owner signs in with SIWE, mints an IP-pinned, expiring
trade key. Agent
loads it from a secret store.Execute
Place via
/perps/orders (or /perps/quotes/bulk with cancelAll for
ladders), always with a clientOrderId.Back to AI agents overview
Revisit the concepts: the agent loop, scopes, and server-side risk.