Documentation Index
Fetch the complete documentation index at: https://docs.context.markets/llms.txt
Use this file to discover all available pages before exploring further.
API reference
The Context API provides programmatic access to markets, orders, and portfolio data. All endpoints use the v2 API.
Base URL
Mainnet:
https://api.context.markets/v2
Testnet:
https://api-testnet.context.markets/v2
If you do not override the chain or base URL, SDK HTTP requests default to the mainnet base URL.
Authentication
Most endpoints require an API key passed as a Bearer token in the Authorization header:
Authorization: Bearer your-api-key
Content-Type: application/json
Get an API key from Profile → Settings at context.markets. See API keys for details.
Public endpoints (no auth required):
| Method | Path | Description |
|---|
GET | /activity | Global activity feed |
GET | /markets | List markets |
GET | /markets/search | Search markets |
GET | /markets/:id | Get market details |
GET | /markets/:id/activity | Get market activity |
GET | /markets/:id/oracle | Get oracle summary |
GET | /markets/:id/oracle/quotes | List oracle quotes |
POST | /markets/:id/oracle/quotes | Request a new oracle quote |
GET | /markets/:id/oracle/quotes/latest | Get the latest oracle quote |
GET | /markets/:id/orderbook | Get the orderbook snapshot |
GET | /markets/:id/prices | Get price history |
GET | /markets/:id/quotes | Get current bid and ask quotes |
POST | /markets/:id/simulate | Simulate a market trade |
Authenticated endpoints (API key required):
| Method | Path | Description |
|---|
GET | /orders | List orders |
POST | /orders | Create an order |
GET | /orders/recent | List recent orders |
GET | /orders/:id | Get an order by id |
POST | /orders/cancel | Cancel an order |
POST | /orders/cancel-replace | Cancel and replace an order |
POST | /orders/bulk | Run mixed bulk order operations |
POST | /orders/bulk/create | Bulk-create orders |
POST | /orders/bulk/cancel | Bulk-cancel orders |
POST | /orders/simulate | Simulate order execution |
GET | /portfolio/:address | Get portfolio summary |
GET | /portfolio/:address/claimable | Get claimable positions |
GET | /portfolio/:address/positions | Get portfolio positions |
GET | /portfolio/:address/stats | Get portfolio stats |
GET | /balance | Get an ERC-20 balance |
GET | /balance/:address | Get balance summary for an address |
GET | /balance/settlement | Get settlement balance |
POST | /balance/mint-test-usdc | Mint testnet collateral |
GET | /account/migration | Get migration status for the API key user or an authorized wallet |
POST | /account/migration/start | Start migration for the API key user or an authorized wallet |
POST | /account/migration/migrate-funds | Submit signed funds migration actions |
POST | /account/migration/restore-orders | Restore retired legacy limit orders as new v2 orders |
POST | /account/migration/dismiss-orders | Dismiss failed or unwanted migration restorations |
POST | /gasless/operator | Relay setOperatorBySig |
POST | /gasless/deposit-with-permit | Relay depositWithPermit to Holdings |
POST /balance/mint-test-usdc is testnet-only and is limited to 100 requests/hour per API key.
Migration endpoints default to the API key user’s primary wallet. Some mutation requests also accept an explicit address override, which requires a signed wallet authorization payload.
When migration is active, wallets that still have legacy balances, legacy open orders, or pending/failed restorations cannot continue normal trading through the API. Those wallets receive 409 responses on:
POST /orders
POST /orders/bulk/create
POST /orders/bulk
POST /orders/cancel-replace
Pure cancel flows remain available:
POST /orders/cancel
POST /orders/bulk/cancel
POST /gasless/operator defaults to Settlement V2 when migration is active, and explicit legacy settlementVersion: 1 approvals are rejected.
Market creation endpoints (API key with can_create_markets permission):
| Method | Path | Description |
|---|
POST | /questions | Submit a question for market creation |
POST | /questions/agent-submit | Submit a market draft directly |
GET | /questions/submissions/:id | Poll submission status |
POST | /markets/create | Create a market from a processed question |
Content types
- Request bodies:
application/json
- Orderbook streaming:
text/event-stream (via Accept header)
All responses are JSON with consistent structure:
Success response
{
"markets": [...],
"cursor": "..."
}
Error response
{
"message": "Error description",
"code": "ERROR_CODE"
}
Bulk operation errors
{
"errors": [
{
"index": 0,
"error": "description",
"operation": "create"
}
]
}
HTTP status codes
| Code | Description |
|---|
| 200 | Success |
| 201 | Created (new order) |
| 400 | Bad Request (validation error, invalid signature) |
| 403 | Forbidden (missing required permission) |
| 404 | Not Found |
| 409 | Conflict (duplicate order) |
| 429 | Rate Limited |
| 500 | Internal Server Error |
The API uses cursor-based pagination for list endpoints. Cursors are opaque strings - don’t parse or construct them manually.
GET /markets?limit=50&cursor=...
Response includes the next cursor:
{
"markets": [...],
"cursor": "next-page-cursor"
}
When cursor is null, you’ve reached the end of the results.
Price and size encoding
All prices and sizes use 6 decimal places (USDC precision):
| Human readable | Encoded value |
|---|
| $0.50 | 500000 |
| $0.01 | 10000 |
| 1 share | 1000000 |
| 0.5 shares | 500000 |
Quotes and orderbook endpoints return prices in cents (0-100) for convenience.
BigInt handling
All numeric values that could exceed JavaScript’s safe integer range (prices, sizes, balances) are returned as strings:
{
"price": "500000",
"size": "1000000"
}
Always parse these as BigInt or use a decimal library for calculations.
Addresses and hashes
All Ethereum addresses and hashes are returned as checksummed hex strings:
{
"marketId": "0x1234567890abcdef...",
"trader": "0xAbCdEf1234567890..."
}
Orderbook polling
The GET /markets/:id/orderbook endpoint returns a JSON snapshot with ETag support for conditional requests. Use If-None-Match to avoid re-fetching unchanged data:
curl -H "If-None-Match: \"abc123\"" \
https://api.context.markets/v2/markets/{id}/orderbook
# Returns 304 Not Modified if unchanged