Markets

The Markets API provides access to prediction market data, including market listings with filtering and pagination options.

Get Markets List

Retrieve a paginated list of markets with filtering options.

Get list of markets (paginated, status=live, sorted by createdAt, supports partial name search via ?search=)

get
Query parameters
pagestringOptional

Page number

Default: 1Example: 1Pattern: ^\d+$
pageSizestringOptional

Page size

Default: 20Example: 20Pattern: ^\d+$
sortstring · enumOptional

Sort by createdAt

Default: descExample: descPossible values:
statusstringOptional

Comma-separated list of statuses (e.g. live,approved,closed)

Default: live,approvedExample: live,approved
searchstring · min: 1 · max: 100Optional

Partial name search for market (case-insensitive, matches any part of the name)

Responses
200

List of markets

application/json
get
GET /api/v1/markets HTTP/1.1
Host: 
Accept: */*
{
  "items": [
    {
      "id": "market-uuid",
      "name": "Market Name",
      "slug": "market-name",
      "categoryId": "text",
      "type": "text",
      "rules": "text",
      "status": "text",
      "tradingStatus": "text",
      "expiresAt": "2024-08-05T12:00:00Z",
      "contractAddress": "text",
      "volume": "text",
      "views": "text",
      "coverImageUrl": "text",
      "createdAt": "2024-08-05T12:00:00Z",
      "outcomes": [
        {
          "id": "outcome-uuid",
          "name": "Yes",
          "volume": "text",
          "lastPrice": "text",
          "positionId": "text"
        }
      ]
    }
  ],
  "total": 100,
  "page": 1,
  "pageSize": 20
}

Get Market Detail

Retrieve detailed information about a specific market by its ID.

Get market detail by marketId

get
Path parameters
marketIdstringRequired

Market ID

Example: market-uuid
Responses
200

Market detail

application/json
get
GET /api/v1/markets/{marketId} HTTP/1.1
Host: 
Accept: */*
{
  "id": "market-uuid",
  "name": "Market Name",
  "slug": "market-name",
  "categoryId": "text",
  "type": "text",
  "rules": "text",
  "status": "text",
  "tradingStatus": "text",
  "expiresAt": "2024-08-05T12:00:00Z",
  "contractAddress": "text",
  "volume": "text",
  "views": "text",
  "coverImageUrl": "text",
  "createdAt": "2024-08-05T12:00:00Z",
  "outcomes": [
    {
      "id": "outcome-uuid",
      "name": "Yes",
      "volume": "text",
      "lastPrice": "text",
      "positionId": "text"
    }
  ]
}

Market Status

Markets can have the following statuses:

Status
Description

live

Market is open for trading

active

Market is active but may have trading restrictions

closed

Market is closed for trading

disputing

Market resolution is being disputed

resolved

Market has been resolved

resolution_proposed

Resolution has been proposed, awaiting confirmation

Code Examples

Fetch Active Markets

const API_KEY = 'YOUR_API_KEY';
const BASE_URL = 'https://engine.xmarket.app/api/v1';

async function getActiveMarkets() {
  const response = await fetch(
    `${BASE_URL}/markets?status=live&pageSize=50`,
    {
      headers: {
        'x-api-key': API_KEY,
        'Content-Type': 'application/json'
      }
    }
  );
  
  const data = await response.json();
  return data.items;
}

Get Market Detail

async function getMarketDetail(marketId) {
  const response = await fetch(
    `${BASE_URL}/markets/${marketId}`,
    {
      headers: {
        'x-api-key': API_KEY,
        'Content-Type': 'application/json'
      }
    }
  );
  
  if (!response.ok) {
    throw new Error(`Market not found: ${response.status}`);
  }
  
  const market = await response.json();
  console.log(`Market: ${market.name}`);
  console.log(`Status: ${market.status}`);
  console.log(`Outcomes: ${market.outcomes.length}`);
  return market;
}

// Example usage
const market = await getMarketDetail('market-uuid-here');

Filter Markets by Status

async function getMarketsByStatus(status) {
  const response = await fetch(
    `${BASE_URL}/markets?status=${status}&page=1&pageSize=100`,
    {
      headers: {
        'x-api-key': API_KEY,
        'Content-Type': 'application/json'
      }
    }
  );
  
  const data = await response.json();
  console.log(`Found ${data.total} ${status} markets`);
  return data.items;
}

// Get all resolved markets
const resolvedMarkets = await getMarketsByStatus('resolved');

// Get markets in dispute
const disputingMarkets = await getMarketsByStatus('disputing');

Best Practices

  1. Caching: Cache market data appropriately as metadata doesn't change frequently

  2. Pagination: Use pagination for large result sets to improve performance

  3. Error Handling: Implement retry logic for transient network errors

  4. Rate Limiting: Respect API rate limits (100 req/min, 20 req/sec burst)

  5. Data Validation: Always validate market and outcome IDs before using them

Last updated

Was this helpful?