DeFiLlama Integration
Access DeFiLlama's comprehensive DeFi data through the Axol API, including TVL, yields, and DEX volumes.
Endpoints
Get TVL Data
GET /v1/integrations/defillama/metrics/tvl
Returns total value locked across protocols and chains.
Query Parameters
| Parameter | Type | Description |
|---|---|---|
protocol | string | Filter by protocol name |
chain | string | Filter by chain |
Response
{
"success": true,
"data": {
"total_tvl_usd": 150000000000,
"timestamp": "2026-01-15T10:30:00Z",
"protocols": [
{
"name": "lido",
"tvl_usd": 25000000000,
"chains": ["ethereum", "polygon"]
},
{
"name": "aave",
"tvl_usd": 12000000000,
"chains": ["ethereum", "polygon", "arbitrum", "optimism"]
}
],
"chains": {
"ethereum": 80000000000,
"polygon": 5000000000,
"arbitrum": 8000000000
}
}
}
Get Yield Opportunities
GET /v1/integrations/defillama/metrics/yields
Returns yield farming opportunities across DeFi.
Query Parameters
| Parameter | Type | Description |
|---|---|---|
chain | string | Filter by chain |
project | string | Filter by project |
min_apy | float | Minimum APY |
min_tvl | float | Minimum TVL in USD |
stablecoin | boolean | Only stablecoin pools |
Response
{
"success": true,
"data": {
"pools": [
{
"pool": "USDC-USDT",
"project": "curve",
"chain": "ethereum",
"apy": 5.2,
"apy_base": 2.1,
"apy_reward": 3.1,
"tvl_usd": 500000000,
"stable": true
},
{
"pool": "ETH-stETH",
"project": "curve",
"chain": "ethereum",
"apy": 4.5,
"apy_base": 4.5,
"apy_reward": 0,
"tvl_usd": 2000000000,
"stable": false
}
],
"count": 2
}
}
Get DEX Volumes
GET /v1/integrations/defillama/metrics/volumes
Returns DEX trading volumes.
Query Parameters
| Parameter | Type | Description |
|---|---|---|
chain | string | Filter by chain |
dex | string | Filter by DEX |
period | string | Time period (24h, 7d, 30d) |
Response
{
"success": true,
"data": {
"total_24h_usd": 5000000000,
"dexes": [
{
"name": "uniswap",
"volume_24h_usd": 2000000000,
"volume_7d_usd": 15000000000,
"chains": ["ethereum", "arbitrum", "polygon", "optimism", "base"]
},
{
"name": "curve",
"volume_24h_usd": 500000000,
"volume_7d_usd": 3500000000,
"chains": ["ethereum", "polygon", "arbitrum"]
}
]
}
}
Get Market Summary
GET /v1/integrations/defillama/metrics/summary
Returns a comprehensive market summary.
Response
{
"success": true,
"data": {
"timestamp": "2026-01-15T10:30:00Z",
"tvl": {
"total_usd": 150000000000,
"change_24h_percent": 2.5
},
"volume": {
"total_24h_usd": 5000000000,
"change_24h_percent": -5.2
},
"top_protocols": [
{"name": "lido", "tvl_usd": 25000000000},
{"name": "aave", "tvl_usd": 12000000000},
{"name": "makerdao", "tvl_usd": 8000000000}
],
"top_chains": [
{"name": "ethereum", "tvl_usd": 80000000000},
{"name": "bsc", "tvl_usd": 5000000000},
{"name": "arbitrum", "tvl_usd": 8000000000}
]
}
}
Swap Endpoints
Get Swap Quote
GET /v1/integrations/defillama/swap/quote
Get the best swap route and quote using DeFiLlama's aggregator.
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
chain | string | Yes | Chain ID |
from_token | string | Yes | From token address |
to_token | string | Yes | To token address |
amount | string | Yes | Amount in wei |
slippage | float | No | Slippage tolerance (default 0.5%) |
Response
{
"success": true,
"data": {
"from_token": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"to_token": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"from_amount": "1000000000000000000",
"to_amount": "3000000000",
"to_amount_min": "2985000000",
"price_impact": 0.05,
"route": [
{
"dex": "uniswap_v3",
"pool": "0x...",
"from": "WETH",
"to": "USDC"
}
],
"gas_estimate": 150000
}
}
Code Examples
Python - TVL Tracker
import requests
class DeFiLlamaClient:
def __init__(self, api_key: str):
self.api_key = api_key
self.base_url = "https://api.axol.io/api/v1/integrations/defillama"
self.headers = {"X-API-Key": api_key}
def get_tvl(self, chain: str = None, protocol: str = None) -> dict:
params = {}
if chain:
params["chain"] = chain
if protocol:
params["protocol"] = protocol
response = requests.get(
f"{self.base_url}/metrics/tvl",
headers=self.headers,
params=params
)
return response.json()["data"]
def get_yields(
self,
chain: str = None,
min_apy: float = None,
stablecoin: bool = None
) -> list:
params = {}
if chain:
params["chain"] = chain
if min_apy:
params["min_apy"] = min_apy
if stablecoin is not None:
params["stablecoin"] = stablecoin
response = requests.get(
f"{self.base_url}/metrics/yields",
headers=self.headers,
params=params
)
return response.json()["data"]["pools"]
def find_best_yields(self, min_tvl: float = 1000000) -> list:
"""Find highest APY pools with minimum TVL."""
pools = self.get_yields()
filtered = [p for p in pools if p["tvl_usd"] >= min_tvl]
return sorted(filtered, key=lambda x: x["apy"], reverse=True)[:10]
# Usage
client = DeFiLlamaClient(api_key="YOUR_KEY")
# Get total TVL
tvl = client.get_tvl()
print(f"Total DeFi TVL: ${tvl['total_tvl_usd']:,.0f}")
# Find best stablecoin yields
stable_yields = client.get_yields(stablecoin=True, min_apy=3.0)
for pool in stable_yields[:5]:
print(f"{pool['project']} {pool['pool']}: {pool['apy']:.2f}% APY")
TypeScript - Market Dashboard
interface TVLData {
total_tvl_usd: number;
protocols: Array<{ name: string; tvl_usd: number }>;
chains: Record<string, number>;
}
interface YieldPool {
pool: string;
project: string;
chain: string;
apy: number;
tvl_usd: number;
stable: boolean;
}
class DeFiDashboard {
private apiKey: string;
private baseUrl = 'https://api.axol.io/api/v1/integrations/defillama';
constructor(apiKey: string) {
this.apiKey = apiKey;
}
private async fetch<T>(path: string, params?: Record<string, string>): Promise<T> {
const url = new URL(`${this.baseUrl}${path}`);
if (params) {
Object.entries(params).forEach(([k, v]) => url.searchParams.set(k, v));
}
const response = await fetch(url.toString(), {
headers: { 'X-API-Key': this.apiKey }
});
const data = await response.json();
return data.data;
}
async getTVL(chain?: string): Promise<TVLData> {
return this.fetch('/metrics/tvl', chain ? { chain } : undefined);
}
async getYields(options?: { chain?: string; minApy?: number }): Promise<YieldPool[]> {
const params: Record<string, string> = {};
if (options?.chain) params.chain = options.chain;
if (options?.minApy) params.min_apy = options.minApy.toString();
const data = await this.fetch<{ pools: YieldPool[] }>('/metrics/yields', params);
return data.pools;
}
async getSummary(): Promise<any> {
return this.fetch('/metrics/summary');
}
}
// Usage
const dashboard = new DeFiDashboard(process.env.AXOL_API_KEY!);
const summary = await dashboard.getSummary();
console.log(`Total TVL: $${(summary.tvl.total_usd / 1e9).toFixed(1)}B`);
console.log(`24h Change: ${summary.tvl.change_24h_percent.toFixed(2)}%`);
const yields = await dashboard.getYields({ minApy: 5 });
console.log(`Found ${yields.length} pools with 5%+ APY`);
Best Practices
1. Cache Results
DeFiLlama data updates every few minutes. Cache responses:
from functools import lru_cache
import time
@lru_cache(maxsize=100)
def get_cached_tvl(ttl_hash: int) -> dict:
return client.get_tvl()
def get_tvl_with_cache(cache_seconds: int = 60) -> dict:
ttl_hash = int(time.time() / cache_seconds)
return get_cached_tvl(ttl_hash)
2. Filter for Relevant Data
Don't fetch everything if you only need specific data:
# Only get Ethereum yields above 5% APY
yields = client.get_yields(chain="ethereum", min_apy=5.0)
3. Handle Rate Limits
import time
def fetch_with_retry(func, *args, max_retries=3):
for i in range(max_retries):
try:
return func(*args)
except requests.exceptions.HTTPError as e:
if e.response.status_code == 429:
time.sleep(2 ** i)
else:
raise
See Also
- 1inch Integration - DEX aggregator
- DeFi Liquidations - Liquidation monitoring