Skip to Content

Markets API

Complete reference for prediction markets and perpetual futures APIs.

Prediction Markets

Get Active Markets

GET /api/markets/predictions

Query Parameters:

  • status (optional): Filter by status (active, resolved)
  • userId (optional): Include user positions

Response:

{ "success": true, "questions": [ { "id": "question-123", "questionNumber": 42, "text": "Will Bitcoin reach $100k by end of 2024?", "status": "active", "yesShares": 1250.5, "noShares": 1850.2, "createdDate": "2024-11-01T00:00:00Z", "resolutionDate": "2024-12-31T23:59:59Z", "userPosition": { "id": "pos-456", "side": "YES", "shares": 50, "avgPrice": 0.62, "currentPrice": 0.65, "unrealizedPnL": 7.5 } } ], "count": 15 }

Buy Shares

POST /api/markets/predictions/{id}/buy

Request Body:

{ "outcome": "YES", "amount": 100 }

Response:

{ "success": true, "position": { "id": "pos-789", "side": "YES", "shares": 38.46, "avgPrice": 0.65, "costBasis": 100 }, "newBalance": 900, "fees": { "total": 2, "platform": 1, "referrer": 1 } }

Sell Shares

POST /api/markets/predictions/{id}/sell

Request Body:

{ "positionId": "pos-789", "shares": 20 }

Response:

{ "success": true, "proceeds": 52.50, "realizedPnL": 2.50, "remainingShares": 18.46, "newBalance": 952.50 }

Perpetual Futures

Get Available Tickers

GET /api/markets/perps

Response:

{ "success": true, "tickers": [ { "ticker": "TECH", "organizationId": "org-123", "name": "Tech Corp", "currentPrice": 125.50, "change24h": 2.5, "changePercent24h": 2.03, "volume24h": 1250000, "fundingRate": 0.0001 } ] }

Open Position

POST /api/markets/perps/open

Request Body:

{ "ticker": "TECH", "side": "long", "size": 1000, "leverage": 10 }

Response:

{ "success": true, "position": { "id": "perp-456", "ticker": "TECH", "side": "long", "entryPrice": 125.50, "size": 1000, "leverage": 10, "liquidationPrice": 113.95, "margin": 100, "unrealizedPnL": 0 }, "newBalance": 900 }

Close Position

POST /api/markets/perps/{positionId}/close

Response:

{ "success": true, "exitPrice": 128.75, "realizedPnL": 25.50, "fundingPaid": -1.20, "netPnL": 24.30, "newBalance": 924.30 }

Get User Positions

GET /api/markets/positions/{userId}

Response:

{ "success": true, "predictions": [ { "id": "pos-123", "marketId": "market-456", "question": "Will Bitcoin reach $100k?", "side": "YES", "shares": 50, "avgPrice": 0.62, "currentPrice": 0.65, "unrealizedPnL": 7.5 } ], "perps": [ { "id": "perp-789", "ticker": "TECH", "side": "long", "size": 1000, "leverage": 10, "entryPrice": 125.50, "currentPrice": 128.75, "unrealizedPnL": 25.50, "liquidationPrice": 113.95 } ], "totalPnL": 33.00 }

Trading Pools

Get All Pools

GET /api/pools

Response:

{ "success": true, "pools": [ { "id": "pool-123", "npcActorId": "actor-456", "name": "Momentum Masters", "description": "High-frequency momentum trading", "totalValue": 125000, "lifetimePnL": 25000, "performanceFeeRate": 0.05, "isActive": true, "priceChange24h": 3.2, "volume24h": 15000 } ] }

Deposit to Pool

POST /api/pools/{id}/deposit

Request Body:

{ "amount": 1000 }

Response:

{ "success": true, "deposit": { "id": "deposit-789", "poolId": "pool-123", "amount": 1000, "shares": 8.0, "sharePrice": 125.0 }, "newBalance": 9000 }

Withdraw from Pool

POST /api/pools/{id}/withdraw

Request Body:

{ "depositId": "deposit-789", "shares": 4.0 }

Response:

{ "success": true, "withdrawal": { "shares": 4.0, "value": 520.0, "pnl": 20.0, "performanceFee": 1.0 }, "newBalance": 9519.0 }

Error Responses

Insufficient Balance

{ "success": false, "error": { "code": "INSUFFICIENT_BALANCE", "message": "Insufficient balance for trade", "details": { "required": 100, "available": 50 } } }

Market Not Found

{ "success": false, "error": { "code": "MARKET_NOT_FOUND", "message": "Market not found", "details": { "marketId": "market-999" } } }

Invalid Trade Size

{ "success": false, "error": { "code": "INVALID_TRADE_SIZE", "message": "Trade size must be positive", "details": { "provided": -10 } } }

Rate Limits

Markets API limits:

EndpointLimitWindow
GET predictions100/min60s
Buy/Sell30/min60s
Open perp20/min60s
Close perp30/min60s

Next Steps

Last updated on