All traffic goes through the OCX API gateway at
https://api.ocx.global, written below as $API_BASE / API_BASE. Prices and quantities are JSON strings — keep them as strings end to end. Quantities are whole contracts. Market ids change as contracts expire; read them from /fut/markets.Step 1 — Sign in and get a session token
The agent signs a SIWE message with a wallet key it controls and keeps the session token from theastra_session cookie. Authentication lists the required message fields and has a complete Node sign-in example (viem + siwe); wrap it in a signIn() function that returns the token.
JavaScript
Step 2 — Read the market
Market data needs no auth. Discover markets, then read the book and stats for the one you want to trade.Step 3 — Size the order with a preview
Always dry-run before you commit.preview returns the notional, the estimated fee, and — critically — whether the order would pass the server-side margin check. It has no side effects.
boolean
Whether the order would pass the margin check. If
false, read reason and
resize or fund — do not retry the same order.string
Margin the order needs.
string
Estimated fee for this order, with
feePerLot and feeRole (maker for post-only orders, otherwise taker).string
quantity ×
contractSize × price.Step 4 — Submit the order
With an approved preview, place the order. Set aclientOrderId so a network
retry can never create a duplicate.
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 not at all.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.Conditional orders
Conditional orders
stopPrice, stopLossPrice, or takeProfitPrice make the order conditional: it is held and submitted once the OCX book mid reaches the trigger. See Place an order for the trigger directions.Step 5 — Monitor fills over the stream
Open one connection to the futures account stream. On connect you receive asnapshot of your recent trades and positions across all futures markets; after that, delta events push new fills and position upserts as they happen. A fill shows up as a trade plus a position delta — that’s your signal to rebalance.
cURL
EventSource cannot send an Authorization header, so read the stream with fetch — the Fill stream guide has a complete reader with gap detection.
Between stream events, reconcile with the pull endpoints when you need certainty:
Step 6 — Manage risk and shut down cleanly
Risk is enforced server-side, but your agent still owns its limits. Track NLV and margin headroom, de-risk proactively, and always have a kill path.cURL
JavaScript
The full loop
1
Provision
Create a dedicated wallet for the agent, fund it, and store its key in a secret manager.
2
Sign in & subscribe
Sign in with SIWE, cache the market list and fee schedule, and open the futures account stream.
3
Decide & size
Compute a signal, then
preview to confirm margin, fee, and approval.4
Execute
Place via
/fut/orders, always with a clientOrderId.5
React
Fold in fills and position deltas from the stream; adjust inventory.
6
Guard
Enforce your own limits; cancel-all or
positions/close on breach, disconnect, or shutdown; renew the session before it expires.Back to AI agents overview
Revisit the concepts: the agent loop, authentication, and server-side risk.