Overview
The Darex API uses API key authentication for all requests. API keys are tied to your account and can be managed through the dashboard.
Getting an API Key
Navigate to API Keys
Go to Settings → API Keys in your dashboard
Generate a New Key
Click “Generate New API Key” and give it a descriptive nameExample names:
production-app
staging-environment
development-local
Copy Your Key
Important: Copy the key immediately - it will only be shown once!dx_sk_live_1234567890abcdefghijklmnopqrstuvwxyz
Store Securely
Store your API key in environment variables, never hardcode it:# .env
DAREX_API_KEY=dx_sk_live_1234567890abcdefghijklmnopqrstuvwxyz
Using API Keys
In HTTP Requests
Include your API key in the X-API-Key header:
curl -H "X-API-Key: dx_sk_live_1234567890abcdefghijklmnopqrstuvwxyz" \
https://api.darex.com/api/v1/instruments
With JavaScript/TypeScript
const API_KEY = process.env.DAREX_API_KEY;
async function fetchInstruments() {
const response = await fetch('https://api.darex.com/api/v1/instruments', {
headers: {
'X-API-Key': API_KEY,
'Content-Type': 'application/json',
},
});
if (!response.ok) {
throw new Error(`API error: ${response.status}`);
}
return response.json();
}
With Python
import os
import requests
API_KEY = os.environ['DAREX_API_KEY']
def fetch_instruments():
response = requests.get(
'https://api.darex.com/api/v1/instruments',
headers={
'X-API-Key': API_KEY,
'Content-Type': 'application/json'
}
)
response.raise_for_status()
return response.json()
With SDK
import { DarexClient } from '@darex/sdk';
const client = new DarexClient({
apiKey: process.env.DAREX_API_KEY,
});
// SDK handles authentication automatically
const instruments = await client.instruments.list();
API Key Types
Test Keys
Prefix: dx_sk_test_
- Use in development and testing
- Access to test environment only
- Unlimited requests
- No charges
# Test key example
dx_sk_test_1234567890abcdefghijklmnopqrstuvwxyz
Live Keys
Prefix: dx_sk_live_
- Use in production
- Access to mainnet data
- Subject to rate limits
- Charges apply
# Live key example
dx_sk_live_1234567890abcdefghijklmnopqrstuvwxyz
Managing API Keys
View All Keys
const response = await fetch('https://api.darex.com/api/v1/auth/keys', {
headers: {
'X-API-Key': API_KEY,
},
});
const { data } = await response.json();
// Returns list of all your keys with metadata
Response:
{
"data": [
{
"id": "key_123abc",
"name": "production-app",
"prefix": "dx_sk_live_",
"lastUsed": "2024-01-15T14:30:00Z",
"createdAt": "2024-01-01T10:00:00Z",
"expiresAt": null,
"status": "active"
}
]
}
Create a New Key
const response = await fetch('https://api.darex.com/api/v1/auth/keys', {
method: 'POST',
headers: {
'X-API-Key': API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: 'staging-environment',
expiresAt: '2024-12-31T23:59:59Z', // Optional
}),
});
const { data } = await response.json();
console.log('New API key:', data.key);
Response:
{
"data": {
"id": "key_456def",
"name": "staging-environment",
"key": "dx_sk_live_1234567890abcdefghijklmnopqrstuvwxyz",
"prefix": "dx_sk_live_",
"createdAt": "2024-01-15T15:00:00Z",
"expiresAt": "2024-12-31T23:59:59Z"
}
}
The full API key is only returned once during creation. Store it securely!
Rate Limiting
Rate limits are enforced per API key:
// Response headers
{
"X-RateLimit-Limit": "10000",
"X-RateLimit-Remaining": "9850",
"X-RateLimit-Reset": "1642261200"
}
Error Responses
401 Unauthorized
Missing API key:
{
"error": {
"code": "UNAUTHORIZED",
"message": "API key is required. Include it in the X-API-Key header.",
"details": {
"timestamp": "2024-01-15T14:30:00Z"
}
}
}
Invalid API key:
{
"error": {
"code": "INVALID_API_KEY",
"message": "The provided API key is invalid or has been revoked.",
"details": {
"timestamp": "2024-01-15T14:30:00Z"
}
}
}
403 Forbidden
Insufficient permissions:
{
"error": {
"code": "FORBIDDEN",
"message": "Your API key does not have permission to access this resource.",
"details": {
"timestamp": "2024-01-15T14:30:00Z"
}
}
}
429 Too Many Requests
Rate limit exceeded:
{
"error": {
"code": "RATE_LIMIT_EXCEEDED",
"message": "You have exceeded your API rate limit.",
"details": {
"limit": 10000,
"resetAt": "2024-01-15T15:00:00Z"
}
}
}
Next Steps