$npx -y skills add agiprolabs/claude-trading-skills --skill defillama-apiFree DeFi analytics across all chains — TVL, token prices, DEX volumes, fees/revenue, stablecoins, and bridges
| 1 | # DeFiLlama API — DeFi Macro Analytics |
| 2 | |
| 3 | DeFiLlama is the largest DeFi TVL aggregator. Its API is **free with no authentication** for most endpoints — covering TVL, token prices, DEX volumes, fees/revenue, stablecoins, and bridges across all chains. |
| 4 | |
| 5 | ## Quick Start |
| 6 | |
| 7 | ```python |
| 8 | import httpx |
| 9 | |
| 10 | # No auth required for free endpoints |
| 11 | BASE = "https://api.llama.fi" |
| 12 | COINS = "https://coins.llama.fi" |
| 13 | |
| 14 | # Current TVL for a protocol |
| 15 | tvl = httpx.get(f"{BASE}/tvl/raydium").json() |
| 16 | print(f"Raydium TVL: ${tvl:,.0f}") |
| 17 | |
| 18 | # Token prices (multi-chain) |
| 19 | resp = httpx.get(f"{COINS}/prices/current/solana:So11111111111111111111111111111111111111112") |
| 20 | sol_price = resp.json()["coins"]["solana:So11111111111111111111111111111111111111112"]["price"] |
| 21 | ``` |
| 22 | |
| 23 | ## Base URLs |
| 24 | |
| 25 | | Service | Base URL | Auth | |
| 26 | |---------|----------|------| |
| 27 | | TVL / Protocols | `https://api.llama.fi` | Free | |
| 28 | | Coin Prices | `https://coins.llama.fi` | Free | |
| 29 | | Stablecoins | `https://stablecoins.llama.fi` | Free | |
| 30 | | Yields | `https://yields.llama.fi` | Pro ($300/mo) | |
| 31 | | Bridges | `https://bridges.llama.fi` | Free (list) / Pro (detail) | |
| 32 | | Pro API | `https://pro-api.llama.fi/{KEY}/api/...` | Pro key in URL path | |
| 33 | |
| 34 | **Rate limits**: ~500 requests per 5 minutes (free). Pro: 1,000 req/min, 1M calls/mo. |
| 35 | |
| 36 | ## TVL & Protocol Data |
| 37 | |
| 38 | ```python |
| 39 | # List all protocols with TVL |
| 40 | GET /protocols |
| 41 | # Returns: [{name, slug, tvl, chainTvls, change_1h, change_1d, change_7d, category, chains, ...}] |
| 42 | |
| 43 | # Detailed protocol data with historical TVL |
| 44 | GET /protocol/{slug} |
| 45 | # Returns: Full object with tvl[], tokensInUsd{}, currentChainTvls{}, ... |
| 46 | |
| 47 | # Simple current TVL number |
| 48 | GET /tvl/{slug} |
| 49 | # Returns: plain number (e.g., 150977324562.40) |
| 50 | |
| 51 | # TVL for all chains |
| 52 | GET /v2/chains |
| 53 | # Returns: [{name, tvl, tokenSymbol, chainId, gecko_id}] |
| 54 | |
| 55 | # Historical chain TVL |
| 56 | GET /v2/historicalChainTvl/{chain} |
| 57 | # chain: "Ethereum", "Solana", "Arbitrum", etc. |
| 58 | # Returns: [{date, tvl}] — date is unix timestamp (seconds) |
| 59 | ``` |
| 60 | |
| 61 | ## Token Prices |
| 62 | |
| 63 | Coin identifiers use `{chain}:{address}` format: |
| 64 | - `solana:So11111111111111111111111111111111111111112` (SOL) |
| 65 | - `ethereum:0xdac17f958d2ee523a2206206994597c13d831ec7` (USDT) |
| 66 | - `coingecko:bitcoin` (non-chain lookups) |
| 67 | |
| 68 | ```python |
| 69 | # Current prices (batch) |
| 70 | GET /prices/current/{coins} |
| 71 | # coins: comma-separated identifiers |
| 72 | # Optional: searchWidth (default 4h) |
| 73 | # Returns: {coins: {id: {price, decimals, symbol, timestamp, confidence}}} |
| 74 | |
| 75 | # Historical price at timestamp |
| 76 | GET /prices/historical/{timestamp}/{coins} |
| 77 | # timestamp: unix seconds |
| 78 | |
| 79 | # Price chart |
| 80 | GET /chart/{coins}?period=1d&span=30 |
| 81 | # period: 1d, 4h, 1h |
| 82 | # Returns: {coins: {id: {prices: [{timestamp, price}]}}} |
| 83 | |
| 84 | # Price change percentage |
| 85 | GET /percentage/{coins} |
| 86 | |
| 87 | # First recorded price |
| 88 | GET /prices/first/{coins} |
| 89 | |
| 90 | # Block number at timestamp |
| 91 | GET /block/{chain}/{timestamp} |
| 92 | ``` |
| 93 | |
| 94 | ### Batch Historical Prices |
| 95 | |
| 96 | ```python |
| 97 | # POST for multiple timestamps per coin |
| 98 | POST /batchHistorical |
| 99 | Body: {"coins": {"solana:So11...": [1709251200, 1709337600]}} |
| 100 | ``` |
| 101 | |
| 102 | ## DEX Volumes |
| 103 | |
| 104 | ```python |
| 105 | # All DEXes aggregated |
| 106 | GET /overview/dexs |
| 107 | # Optional: excludeTotalDataChart=true, dataType=dailyVolume |
| 108 | |
| 109 | # Chain-specific |
| 110 | GET /overview/dexs/{chain} |
| 111 | # chain: "Solana", "Ethereum", etc. |
| 112 | |
| 113 | # Specific DEX |
| 114 | GET /summary/dexs/{protocol} |
| 115 | # Returns: {total24h, total7d, total30d, totalAllTime, totalDataChart, ...} |
| 116 | ``` |
| 117 | |
| 118 | ## Fees & Revenue |
| 119 | |
| 120 | ```python |
| 121 | # All protocols |
| 122 | GET /overview/fees |
| 123 | # Optional: dataType=dailyFees|dailyRevenue|dailyUserFees |
| 124 | |
| 125 | # Chain-specific |
| 126 | GET /overview/fees/{chain} |
| 127 | |
| 128 | # Specific protocol |
| 129 | GET /summary/fees/{protocol} |
| 130 | # Returns: {total24h, total7d, methodology{}, totalDataChart[], ...} |
| 131 | ``` |
| 132 | |
| 133 | ## Stablecoins |
| 134 | |
| 135 | ```python |
| 136 | # All stablecoins with supply data |
| 137 | GET https://stablecoins.llama.fi/stablecoins |
| 138 | # Returns: [{name, symbol, pegType, circulating, chainCirculating, price}] |
| 139 | |
| 140 | # Historical market cap |
| 141 | GET https://stablecoins.llama.fi/stablecoincharts/all |
| 142 | |
| 143 | # Chain-specific stablecoin data |
| 144 | GET https://stablecoins.llama.fi/stablecoincharts/{chain} |
| 145 | |
| 146 | # Stablecoin prices (deviation tracking) |
| 147 | GET https://stablecoins.llama.fi/stablecoinprices |
| 148 | ``` |
| 149 | |
| 150 | ## Bridges |
| 151 | |
| 152 | ```python |
| 153 | # List all bridges |
| 154 | GET https://bridges.llama.fi/bridges |
| 155 | # Optional: includeChains=true |
| 156 | # Returns: {bridges: [{name, volume stats, chains, ...}]} |
| 157 | ``` |
| 158 | |
| 159 | ## Common Patterns |
| 160 | |
| 161 | ### Protocol TVL Comparison |
| 162 | |
| 163 | ```python |
| 164 | def compare_protocol_tvl(slugs: list[str]) -> list[dict]: |
| 165 | """Compare TVL across protocols.""" |
| 166 | results = [] |
| 167 | for slug in slugs: |
| 168 | resp = httpx.get(f"https://api.llama.fi/tvl/{slug}", timeout=15.0) |
| 169 | if resp.status_code == 200: |
| 170 | results.append({"protocol": slug, "tvl": resp.json()}) |
| 171 | return sorted(results, key=lambda x: x["tvl"], reverse=True) |
| 172 | ``` |
| 173 | |
| 174 | ### Multi-Token Price Lookup |
| 175 | |
| 176 | ```python |
| 177 | def get_solana_prices(mints: list[str]) -> dict[str, float]: |
| 178 | """Get USD prices for Solana tokens via DeFiLlama.""" |
| 179 | coins = ",".join(f"solana:{m}" for m in mints) |
| 180 | re |