Skip to main content

Orderbook

Get Orderbook Data

Retrieve the orderbook for a specific market outcome.

Endpoint: GET /api/v1/orderbook/{outcomeId}

Path Parameters:

ParameterTypeDescription
outcomeIdstringThe unique outcome identifier

Code Examples

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

async function getOrderbook(outcomeId) {
const response = await fetch(
`${BASE_URL}/orderbook/${outcomeId}`,
{
headers: {
'x-api-key': API_KEY,
'Content-Type': 'application/json'
}
}
);

const orderbook = await response.json();
return orderbook;
}

Get Spread

Retrieve the orderbook spread for a specific market outcome.

Endpoint: GET /api/v1/orderbook/spread/{outcomeId}

Path Parameters:

ParameterTypeDescription
outcomeIdstringThe unique outcome identifier

Best Practices

  1. Polling Frequency: Don't poll too frequently; respect rate limits
  2. Data Caching: Cache orderbook data with appropriate TTL
  3. Error Handling: Handle network errors and invalid responses gracefully
  4. Price Validation: Validate prices are within valid range (0-1)
  5. Depth Analysis: Consider market depth when placing large orders
  6. Real-time Updates: For high-frequency updates, consider WebSocket connections when available

Performance Tips

  • Use pagination to limit response size
  • Cache orderbook data for recently viewed markets
  • Implement exponential backoff for retry logic
  • Consider aggregating multiple outcome orderbooks in parallel
  • Monitor rate limit headers to avoid throttling