Skip to main content

Overview

The Darex REST API provides programmatic access to:
  • Instrument Discovery: Query all available DeFi instruments
  • Metrics & Analytics: Historical APY, TVL, and performance data
  • Protocol Information: Supported protocols and their markets

Base URL

https://api.darex.com/api/v1
Sandbox (Testing):
https://sandbox-api.darex.com/api/v1

Quick Start

Make Your First Request

curl -H "X-API-Key: your-api-key" \
  https://api.darex.com/api/v1/instruments
Response:
{
  "data": [
    {
      "id": "0x00007a69c053a3e1290845e12a3eea14926472ce7f15da324cdf0700056fc04b",
      "protocol": "Aave",
      "token": "USDC",
      "chainId": 31337,
      "apy": 5.2,
      "tvl": "1250000000000",
      "adapterAddress": "0x007e8014867D5686ef6dF63cd7301e5771d1AA8f",
      "yieldToken": "aUSDC",
      "createdAt": "2024-01-15T10:00:00Z",
      "updatedAt": "2024-01-15T14:30:00Z"
    }
  ],
  "meta": {
    "total": 7,
    "page": 1,
    "limit": 10
  }
}

Using TypeScript/JavaScript

const API_KEY = 'your-api-key';
const BASE_URL = 'https://api.darex.com/api/v1';

async function getInstruments() {
  const response = await fetch(`${BASE_URL}/instruments`, {
    headers: {
      'X-API-Key': API_KEY,
      'Content-Type': 'application/json',
    },
  });

  if (!response.ok) {
    throw new Error(`API error: ${response.status}`);
  }

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

// Usage
const instruments = await getInstruments();
console.log(`Found ${instruments.meta.total} instruments`);

Using Python

import requests

API_KEY = 'your-api-key'
BASE_URL = 'https://api.darex.com/api/v1'

def get_instruments():
    headers = {
        'X-API-Key': API_KEY,
        'Content-Type': 'application/json'
    }

    response = requests.get(f'{BASE_URL}/instruments', headers=headers)
    response.raise_for_status()

    return response.json()

# Usage
instruments = get_instruments()
print(f"Found {instruments['meta']['total']} instruments")

Response Format

All API responses follow a consistent structure:

Success Response

{
  "data": {
    // Response data here
  },
  "meta": {
    "timestamp": "2024-01-15T14:30:00Z",
    "requestId": "req_123abc"
  }
}

Paginated Response

{
  "data": [
    // Array of items
  ],
  "meta": {
    "total": 100,
    "page": 1,
    "limit": 10,
    "totalPages": 10,
    "hasMore": true
  }
}

Error Response

{
  "error": {
    "code": "INVALID_API_KEY",
    "message": "The provided API key is invalid",
    "details": {
      "timestamp": "2024-01-15T14:30:00Z",
      "requestId": "req_123abc"
    }
  }
}

Error Codes

Status CodeError CodeDescription
400BAD_REQUESTInvalid request parameters
401UNAUTHORIZEDMissing or invalid API key
403FORBIDDENAPI key doesn’t have required permissions
404NOT_FOUNDResource not found
429RATE_LIMIT_EXCEEDEDToo many requests
500INTERNAL_ERRORServer error

Rate Limiting

API requests are rate limited:
// Rate limit headers included in every response
{
  "X-RateLimit-Limit": "10000",
  "X-RateLimit-Remaining": "9850",
  "X-RateLimit-Reset": "1642261200"
}

Pagination

Most list endpoints support pagination:
# Get page 2 with 20 items per page
curl -H "X-API-Key: your-api-key" \
  "https://api.darex.com/api/v1/instruments?page=2&limit=20"
Parameters:
  • page (default: 1) - Page number
  • limit (default: 10, max: 100) - Items per page

Filtering

Filter instruments by various criteria:
# Filter by protocol
curl -H "X-API-Key: your-api-key" \
  "https://api.darex.com/api/v1/instruments?protocol=Aave"

# Filter by minimum APY
curl -H "X-API-Key: your-api-key" \
  "https://api.darex.com/api/v1/instruments?minApy=5"

# Combine filters
curl -H "X-API-Key: your-api-key" \
  "https://api.darex.com/api/v1/instruments?protocol=Aave&minApy=5&sort=apy:desc"

Sorting

Sort results using the sort parameter:
# Sort by APY descending
?sort=apy:desc

# Sort by TVL ascending
?sort=tvl:asc

# Multiple sort fields
?sort=apy:desc,tvl:desc

Next Steps