Skip to main content

Markets

Get Markets List

Retrieve a paginated list of markets with filtering options.

Endpoint: GET /api/v1/markets

Query Parameters:

ParameterTypeDescription
statusstringFilter by market status (live, active, closed, disputing, resolved, resolution_proposed)
pagenumberPage number for pagination
pageSizenumberNumber of results per page

Get Market Detail

Retrieve detailed information about a specific market by its ID.

Endpoint: GET /api/v1/markets/{marketId}

Path Parameters:

ParameterTypeDescription
marketIdstringThe unique market identifier

Market Status

Markets can have the following statuses:

StatusDescription
liveMarket is open for trading
activeMarket is active but may have trading restrictions
closedMarket is closed for trading
disputingMarket resolution is being disputed
resolvedMarket has been resolved
resolution_proposedResolution 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