Quick Start
Overview
The Xmarket API provides programmatic access to:
- Real-time orderbook data
- Order creation and management
- Market information
- Position tracking
- Trading operations
Base URLs
The API uses two base URLs depending on the endpoint type:
-
Public endpoints (read-only, no authentication required):
https://engine.xmarket.app/api/v1Used for: Markets, Orderbook data
-
Authenticated endpoints (require API key):
https://engine.xmarket.app/openapi/v1Used for: Orders, Positions, Trading operations
Prerequisites
Before you begin, you'll need:
- An Xmarket account
- An API key for authentication
Getting Your API Key
Step 1: Register an Account
Visit Xmarket and create your account if you haven't already.
Step 2: Generate API Key
- Navigate to your account Settings page
- Find the API Management section
- Click Generate New API Key
- Store your API key securely!
Important: Keep your API key secure and never share it publicly or commit it to version control.
Authentication
All API requests require authentication using your API key in the x-api-key header:
x-api-key: YOUR_API_KEY
Making Your First Request
Let's start with a simple request to fetch orderbook data:
- cURL
- Javascript
- Python
curl -X GET \
'https://engine.xmarket.app/api/v1/orderbook/{outcomeId}' \
-H 'x-api-key: YOUR_API_KEY'
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}`,
{
method: 'GET',
headers: {
'x-api-key': API_KEY,
'Content-Type': 'application/json'
}
}
);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return await response.json();
}
// Example usage
getOrderbook('outcome-id')
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
import requests
API_KEY = 'YOUR_API_KEY'
BASE_URL = 'https://engine.xmarket.app/api/v1'
def get_orderbook(outcome_id):
headers = {
'x-api-key': API_KEY,
'Content-Type': 'application/json'
}
response = requests.get(
f'{BASE_URL}/orderbook/{outcome_id}',
headers=headers
)
response.raise_for_status()
return response.json()
# Example usage
try:
orderbook = get_orderbook('outcome-id')
print(orderbook)
except requests.exceptions.RequestException as e:
print(f'Error: {e}')
Error Handling
The API uses standard HTTP status codes to indicate success or failure:
| Status Code | Description |
|---|---|
| 200 | Success |
| 201 | Resource created |
| 400 | Bad Request - Invalid parameters |
| 401 | Unauthorized - Invalid or missing API key |
| 404 | Not Found - Resource doesn't exist |
| 500 | Internal Server Error |
Error responses include a message explaining what went wrong:
{
"message": "Invalid market ID"
}
Rate Limits
To ensure fair usage and system stability, the API implements rate limiting:
- Default limit: 100 requests per minute per API key
When you exceed the rate limit, you'll receive a 429 Too Many Requests response.
Next Steps
Now that you're set up, explore our detailed API documentation:
- Markets API - Browse and search prediction markets
- Orderbook API - View real-time market depth
- Orders API - Create, cancel, and manage orders
- Positions API - Track your trading positions
Support
If you encounter any issues or have questions:
- Check our FAQs
- Contact support through the platform