Trade API Documentation
Overview
The Trade API provides functionality to list markets, get trade quotes, and execute trades on prediction markets.Example
API Endpoints
1. GET /trade/markets - Get All Tradeable Markets
Returns a list of all available prediction markets. Public — no API key required.
Query Parameters:
Example:volumeis normalized server-side (raw / 10^chainDecimals), so it is already in human USD — do not divide it again client-side. This works for 18-decimal collateral too; never hardcode1e6.
2. POST /trade/quote - Get Trade Quote
Get pricing information for a potential trade. Public — no API key required.
Request:
3. POST /trade - Create Trade Intent
Creates a TransactionIntent and returns the data needed to execute the trade.
The response shape depends on the market model:
- AMM markets return an encoded
txblock to sign and send. - CLOB markets return an EIP-712
typedDatablock to sign.
Requires a platform API key. Send it as the
X-Platform-API-Key header (or
Authorization: Bearer <apiKey>). Without it the request is rejected with 401.4. POST /trade/redeem - Execute Redeem
Generate redeem calldata for executing a redeem transaction on resolved markets where the user has winning positions.
Requires a platform API key (
X-Platform-API-Key header, or Authorization: Bearer <apiKey>).5. GET /trade/positions - Get User Positions
Retrieve user positions with pagination support. Supports filtering by active or resolved markets.
Query Parameters:
6. POST /trade/save - Save Trade
After broadcasting a trade transaction, send its transaction hash to this endpoint. Call it right after submitting the transaction — you do not need to wait for the transaction receipt.
Headers:
X-Platform-API-Key: <your platform API key>
Token Approval Process
Before executing trades, users must approve the market maker contract to spend their tokens. This is a standard ERC-20 requirement.Approval Steps
- Check Current Allowance: Query the token contract to see how much the market maker is allowed to spend
- Approve if Needed: If allowance is insufficient, call the
approvefunction on the token contract - Wait for Confirmation: Wait for the approval transaction to be confirmed
- Execute Trade: Proceed with the trade execution
Example Approval Code
Important Notes
- Buy trades require approval: Only buying tokens requires token approval
- Sell trades require ERC1155 setApprovalForAll: Selling conditional tokens require ERC1155 approval, as we are using ERC1155 to represent market shares
- Unlimited approval: The example uses max uint256 for unlimited approval to avoid repeated approval transactions
- Gas costs: Approval transactions require gas fees, so consider this in your UX
Key Notes
- All amounts are handled in base units (6 decimals for USDC)
- The execute endpoint returns transaction data that must be signed and sent by the user’s wallet
- Always simulate transactions before execution to catch potential failures
- Token approval is required before executing any trades
- After broadcasting a trade, send its transaction hash to
/trade/save. Call it right after submitting — you do not need to wait for the transaction receipt. - The API follows RESTful conventions with appropriate HTTP status codes
/tradeand/trade/redeemrequire a platform API key (X-Platform-API-Key);/trade/markets,/trade/quote, and/trade/positionsare public/tradereturns a trade intent — AMM markets include atxblock, CLOB markets includetypedData- Use
/trade/positionsto get a user’s positions - Use
/trade/redeemto get the calldata neccessary to redeem a position - No
/trade/completecall is needed after a trade or redeem — the indexer auto-processes confirmed transactions /trade/saveapplies to trades only (origin attribution); redeems need no save call
- Markets endpoint provides available trading opportunities
- Quote endpoint calculates trade details and pricing
- Execute endpoint prepares blockchain transaction data for the user to sign and send
- Save endpoint records the broadcast trade’s transaction hash for the backend
- Positions endpoint retrieves user’s current positions with pagination
- Redeem endpoint prepares redeem transaction data for winning positions
- Indexer processes confirmed transactions to ensure positions appear in the frontend