Skip to main content

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:
Response:
volume is 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 hardcode 1e6.
Example:

2. POST /trade/quote - Get Trade Quote

Get pricing information for a potential trade. Public — no API key required. Request:
Response:
Example:

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 tx block to sign and send.
  • CLOB markets return an EIP-712 typedData block 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.
Request:
Response:
The AMM tx block no longer includes an account field. Sign and send the transaction from the user’s own wallet (the account you passed in the request).
Example:

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>).
Request:
Response:
Example:

5. GET /trade/positions - Get User Positions

Retrieve user positions with pagination support. Supports filtering by active or resolved markets. Query Parameters:
Response:
Example:

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>
Request:
Response:

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

  1. Check Current Allowance: Query the token contract to see how much the market maker is allowed to spend
  2. Approve if Needed: If allowance is insufficient, call the approve function on the token contract
  3. Wait for Confirmation: Wait for the approval transaction to be confirmed
  4. 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
  • /trade and /trade/redeem require a platform API key (X-Platform-API-Key); /trade/markets, /trade/quote, and /trade/positions are public
  • /trade returns a trade intent — AMM markets include a tx block, CLOB markets include typedData
  • Use /trade/positions to get a user’s positions
  • Use /trade/redeem to get the calldata neccessary to redeem a position
  • No /trade/complete call is needed after a trade or redeem — the indexer auto-processes confirmed transactions
  • /trade/save applies to trades only (origin attribution); redeems need no save call
The API follows a clear pattern where:
  • 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