defillama

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

DefiLlama API

DefiLlama API

Trit: -1 (MINUS - Validator/Data Source) Color: #4A90D9 (Cold blue, 210°)
Comprehensive DeFi data from DefiLlama's API ecosystem.
Trit: -1 (MINUS - 验证器/数据源) Color: #4A90D9 (冷蓝色, 210°)
来自DefiLlama API生态的全面DeFi数据。

Matching Keywords (intent triggers)

匹配关键词(意图触发条件)

Use this skill when users ask about any of the following:
  • TVL: TVL ranking, protocol TVL, chain TVL, TVL changes, DeFi market share
  • Stablecoin yield: stablecoin yield, USDC/USDT APY, low-risk yield pools, safe yield, fixed-income-like DeFi
  • Yield / Farming: APY ranking, yield pool screening, vault yield, lending APY, borrow rates, LSD/LRT yield
  • DEX / Fees / Revenue: DEX volume, protocol fees, protocol revenue, revenue growth, which DEX revenue is growing fastest
  • Flows / Rotation: capital flows, chain inflow/outflow, stablecoin netflow, liquidity rotation
  • Protocol Research: protocol fundamentals, multi-protocol comparison, sector comparison, DeFi snapshot/report
Typical user prompts this skill should match:
  • “Which DEX has seen the strongest revenue growth recently?”
  • “Find me some low-risk stablecoin yield options with decent returns.”
  • “Create a DeFi market snapshot for today (TVL / volume / fees).”
  • “Compare ETH vs SOL on-chain flow changes over the last 30 days.”
当用户询问以下任意内容时可使用该技能:
  • TVL: TVL排名、协议TVL、公链TVL、TVL变动、DeFi市场份额
  • 稳定币收益: 稳定币收益、USDC/USDT APY、低风险收益池、安全收益、类固定收益DeFi
  • 收益 / 挖矿: APY排名、收益池筛选、金库收益、借贷APY、借款利率、LSD/LRT收益
  • DEX / 手续费 / 收入: DEX交易量、协议手续费、协议收入、收入增长、哪款DEX收入增长最快
  • 资金流向 / 轮动: 资金流向、公链流入/流出、稳定币净流量、流动性轮动
  • 协议研究: 协议基本面、多协议对比、赛道对比、DeFi快照/报告
该技能应匹配的典型用户提问:
  • “最近哪款DEX的收入增长最强劲?”
  • “给我找一些收益不错的低风险稳定币收益选项。”
  • “生成今日DeFi市场快照(TVL / 交易量 / 手续费)。”
  • “对比过去30天ETH和SOL的链上流量变化。”

Base URLs

基础URL

APIBase URLAuth
Free API
https://api.llama.fi
None (no key needed)
Pro API
https://pro-api.llama.fi/{API_KEY}
Key in path
/API_KEY/endpoint
Bridge API
https://bridges.llama.fi
None
Key rule: Use
https://api.llama.fi
for all free endpoints (TVL, chains, DEX, fees, prices). Use
https://pro-api.llama.fi/{API_KEY}
ONLY for pro endpoints (yields, derivatives, emissions). Env var:
DEFILLAMA_API_KEY
— used in pro URL path, NOT as HTTP header.
API基础URL鉴权
免费API
https://api.llama.fi
无需鉴权(不需要密钥)
专业版API
https://pro-api.llama.fi/{API_KEY}
密钥放在路径
/API_KEY/endpoint
跨链桥API
https://bridges.llama.fi
无需鉴权
核心规则: 所有免费端点(TVL、公链、DEX、手续费、价格)使用
https://api.llama.fi
专业版端点(收益、衍生品、代币释放)使用
https://pro-api.llama.fi/{API_KEY}
环境变量:
DEFILLAMA_API_KEY
—— 用于专业版URL路径中,作为HTTP请求头传递。

Most Common Endpoints (Start Here)

最常用端点(入门首选)

For 90% of DeFi analytics tasks, use these free endpoints (
api.llama.fi
):
TaskEndpointExample
TVL Top N protocols
GET /protocols
Sort by
.tvl
field
Single protocol detail
GET /protocol/{slug}
e.g.
/protocol/aave
Chain TVL history
GET /v2/historicalChainTvl/{chain}
.date
+
.tvl
fields
DEX volumes
GET /overview/dexs?excludeChart=true
.total24h
,
.total7d
Protocol fees
GET /overview/fees?excludeChart=true
.total24h
All chains TVL
GET /v2/chains
Sum
.tvl
for global total
⚠️ Pro endpoints (
/yields/*
,
/emissions
, etc.) require
DEFILLAMA_API_KEY
in the URL path.
90%的DeFi分析任务都可以使用以下免费端点(
api.llama.fi
)完成:
任务端点示例
TVL排名前N的协议
GET /protocols
.tvl
字段排序
单个协议详情
GET /protocol/{slug}
例如
/protocol/aave
公链TVL历史数据
GET /v2/historicalChainTvl/{chain}
.date
+
.tvl
字段
DEX交易量
GET /overview/dexs?excludeChart=true
.total24h
.total7d
协议手续费
GET /overview/fees?excludeChart=true
.total24h
所有公链TVL
GET /v2/chains
累加
.tvl
得到全局总TVL
⚠️ 专业版端点
/yields/*
/emissions
等)需要在URL路径中传入
DEFILLAMA_API_KEY

Proxy Requirement (sc-proxy)

代理要求(sc-proxy)

When using fake API keys (for example
fake-defillama-key-12345
), requests must go through sc-proxy so the key can be replaced upstream.
  • Env key name:
    DEFILLAMA_API_KEY
  • Auto proxy detection envs:
    PROXY_HOST
    ,
    PROXY_PORT
  • If
    HTTP_PROXY
    /
    HTTPS_PROXY
    are unset, direct requests may hit upstream and return key errors.
当使用测试API密钥(例如
fake-defillama-key-12345
)时,请求必须走sc-proxy,上游服务会自动替换有效密钥。
  • 环境变量名:
    DEFILLAMA_API_KEY
  • 自动代理检测环境变量:
    PROXY_HOST
    PROXY_PORT
  • 如果未设置
    HTTP_PROXY
    /
    HTTPS_PROXY
    ,直接请求上游会返回密钥错误。

Python template (recommended)

Python模板(推荐)

python
import os
import requests

host = os.getenv("PROXY_HOST")
port = os.getenv("PROXY_PORT")
session = requests.Session()
if host and port:
    if ":" in host and not host.startswith("["):
        host = f"[{host}]"  # IPv6-safe
    proxy = f"http://{host}:{port}"
    session.proxies.update({"http": proxy, "https": proxy})
python
import os
import requests

host = os.getenv("PROXY_HOST")
port = os.getenv("PROXY_PORT")
session = requests.Session()
if host and port:
    if ":" in host and not host.startswith("["):
        host = f"[{host}]"  # IPv6-safe
    proxy = f"http://{host}:{port}"
    session.proxies.update({"http": proxy, "https": proxy})

Free endpoint (no key needed):

Free endpoint (no key needed):

r_free = session.get("https://api.llama.fi/protocols", timeout=25) print("Free:", r_free.status_code)
r_free = session.get("https://api.llama.fi/protocols", timeout=25) print("Free:", r_free.status_code)

Pro endpoint (key in URL path):

Pro endpoint (key in URL path):

api_key = os.environ["DEFILLAMA_API_KEY"] r_pro = session.get(f"https://pro-api.llama.fi/{api_key}/yields/pools", timeout=25) print("Pro:", r_pro.status_code)
undefined
api_key = os.environ["DEFILLAMA_API_KEY"] r_pro = session.get(f"https://pro-api.llama.fi/{api_key}/yields/pools", timeout=25) print("Pro:", r_pro.status_code)
undefined

Quick test commands

快速测试命令

bash
set -a && source .env && set +a
python3 - << 'PY'
import os, requests
s = requests.Session()
host, port = os.getenv('PROXY_HOST'), os.getenv('PROXY_PORT')
if host and port:
    if ':' in host and not host.startswith('['):
        host = f'[{host}]'
    p = f'http://{host}:{port}'
    s.proxies.update({'http': p, 'https': p})
bash
set -a && source .env && set +a
python3 - << 'PY'
import os, requests
s = requests.Session()
host, port = os.getenv('PROXY_HOST'), os.getenv('PROXY_PORT')
if host and port:
    if ':' in host and not host.startswith('['):
        host = f'[{host}]'
    p = f'http://{host}:{port}'
    s.proxies.update({'http': p, 'https': p})

Free endpoint

Free endpoint

r1 = s.get('https://api.llama.fi/protocols', timeout=25) print('free /protocols:', r1.status_code)
r1 = s.get('https://api.llama.fi/protocols', timeout=25) print('free /protocols:', r1.status_code)

Pro endpoint

Pro endpoint

k = os.environ['DEFILLAMA_API_KEY'] r2 = s.get(f'https://pro-api.llama.fi/{k}/yields/pools', timeout=25) print('pro /yields/pools:', r2.status_code) PY
undefined
k = os.environ['DEFILLAMA_API_KEY'] r2 = s.get(f'https://pro-api.llama.fi/{k}/yields/pools', timeout=25) print('pro /yields/pools:', r2.status_code) PY
undefined

Quick Reference

快速参考

TVL & Protocols

TVL与协议

bash
undefined
bash
undefined

All protocols with TVL

所有带TVL的协议

GET /protocols
GET /protocols

Single protocol detail

单个协议详情

GET /protocol/{slug}
GET /protocol/{slug}

Chain TVL

公链TVL

GET /v2/chains GET /v2/historicalChainTvl/{chain}
undefined
GET /v2/chains GET /v2/historicalChainTvl/{chain}
undefined

Prices

价格

bash
undefined
bash
undefined

Current prices (chain:address format)

当前价格(格式:公链:地址)

GET /coins/prices/current/{coins}
GET /coins/prices/current/{coins}

Historical

历史价格

GET /coins/prices/historical/{timestamp}/{coins}
GET /coins/prices/historical/{timestamp}/{coins}

Chart data

图表数据

GET /coins/chart/{coins}?period=30d
undefined
GET /coins/chart/{coins}?period=30d
undefined

Yields (Pro)

收益(专业版)

bash
GET /yields/pools           # All yield pools
GET /yields/chart/{pool}    # Pool history
GET /yields/poolsBorrow     # Borrow rates
GET /yields/perps           # Perp funding
GET /yields/lsdRates        # LSD rates
bash
GET /yields/pools           # 所有收益池
GET /yields/chart/{pool}    # 收益池历史数据
GET /yields/poolsBorrow     # 借款利率
GET /yields/perps           # 永续合约资金费率
GET /yields/lsdRates        # LSD收益率

Volume

交易量

bash
GET /overview/dexs?excludeChart=true              # DEX volumes (recommended)
GET /overview/dexs/{chain}?excludeChart=true      # Chain DEX
GET /summary/dexs/{protocol}                       # Protocol detail
GET /overview/options?excludeChart=true           # Options
GET /overview/derivatives?excludeChart=true       # Derivatives (Pro)
bash
GET /overview/dexs?excludeChart=true              # DEX交易量(推荐)
GET /overview/dexs/{chain}?excludeChart=true      # 单公链DEX数据
GET /summary/dexs/{protocol}                       # 协议详情
GET /overview/options?excludeChart=true           # 期权数据
GET /overview/derivatives?excludeChart=true       # 衍生品数据(专业版)

Fees & Revenue

手续费与收入

bash
GET /overview/fees?excludeChart=true              # All fees/revenue (recommended)
GET /overview/fees/{chain}?excludeChart=true      # Chain fees
GET /summary/fees/{protocol}                      # Protocol fees
bash
GET /overview/fees?excludeChart=true              # 所有手续费/收入(推荐)
GET /overview/fees/{chain}?excludeChart=true      # 单公链手续费
GET /summary/fees/{protocol}                      # 协议手续费

dataType: dailyFees | dailyRevenue | dailyHoldersRevenue

dataType可选: dailyFees | dailyRevenue | dailyHoldersRevenue

undefined
undefined

Bridges

跨链桥

bash
undefined
bash
undefined
GET /bridges # All bridges GET /bridge/{id} # Bridge detail GET /bridgevolume/{chain} # Volume by chain GET /transactions/{id} # Bridge txs
undefined
GET /bridges # 所有跨链桥 GET /bridge/{id} # 跨链桥详情 GET /bridgevolume/{chain} # 按公链统计的交易量 GET /transactions/{id} # 跨链桥交易记录
undefined

DAT (Digital Asset Treasury)

DAT(数字资产国库)

bash
GET /dat/institutions               # All institutions
GET /dat/institutions/{symbol}      # e.g., MSTR
bash
GET /dat/institutions               # 所有机构
GET /dat/institutions/{symbol}      # 例如 MSTR

Usage Script

使用脚本

clojure
;; See scripts/defillama.bb for full implementation
(require '[defillama :as dl])

;; TVL
(dl/protocols)
(dl/protocol "aave")
(dl/chain-tvl "Ethereum")

;; Prices
(dl/price "ethereum:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48")
(dl/price-chart "coingecko:ethereum" {:period "30d"})

;; Yields
(dl/yield-pools)
(dl/pool-chart "747c1d2a-c668-4682-b9f9-296708a3dd90")

;; Volumes
(dl/dex-overview)
(dl/dex-protocol "uniswap")

;; Fees
(dl/fees-overview)
(dl/fees-protocol "hyperliquid")
clojure
;; See scripts/defillama.bb for full implementation
(require '[defillama :as dl])

;; TVL
(dl/protocols)
(dl/protocol "aave")
(dl/chain-tvl "Ethereum")

;; Prices
(dl/price "ethereum:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48")
(dl/price-chart "coingecko:ethereum" {:period "30d"})

;; Yields
(dl/yield-pools)
(dl/pool-chart "747c1d2a-c668-4682-b9f9-296708a3dd90")

;; Volumes
(dl/dex-overview)
(dl/dex-protocol "uniswap")

;; Fees
(dl/fees-overview)
(dl/fees-protocol "hyperliquid")

Endpoint Categories

端点分类

Free Endpoints

免费端点

  • /protocols
    ,
    /protocol/{slug}
    ,
    /tvl/{slug}
  • /v2/chains
    ,
    /v2/historicalChainTvl
  • /coins/prices/*
    ,
    /coins/chart/*
  • /overview/dexs
    ,
    /overview/options
  • /overview/fees
    ,
    /summary/fees/*
  • /protocols
    ,
    /protocol/{slug}
    ,
    /tvl/{slug}
  • /v2/chains
    ,
    /v2/historicalChainTvl
  • /coins/prices/*
    ,
    /coins/chart/*
  • /overview/dexs
    ,
    /overview/options
  • /overview/fees
    ,
    /summary/fees/*

Pro Endpoints (API Key Required)

专业版端点(需要API密钥)

  • /yields/*
    - All yield endpoints (stablecoin pools, APY ranking, borrow/perps/LSD)
  • /overview/derivatives
  • /tokenProtocols/{symbol}
  • /inflows/{protocol}/{timestamp}
  • /chainAssets
  • /emissions
    ,
    /emission/{protocol}
  • /categories
    ,
    /forks
    ,
    /oracles
  • /entities
    ,
    /treasuries
  • /hacks
    ,
    /raises
  • /etfs/*
    ,
    /dat/*
  • Bridge endpoints on bridges.llama.fi
  • /yields/*
    - 所有收益相关端点(稳定币池、APY排名、借款/永续合约/LSD)
  • /overview/derivatives
  • /tokenProtocols/{symbol}
  • /inflows/{protocol}/{timestamp}
  • /chainAssets
  • /emissions
    ,
    /emission/{protocol}
  • /categories
    ,
    /forks
    ,
    /oracles
  • /entities
    ,
    /treasuries
  • /hacks
    ,
    /raises
  • /etfs/*
    ,
    /dat/*
  • bridges.llama.fi上的跨链桥端点

Response Patterns

返回格式示例

TVL Response

TVL返回

json
{"id": "2269", "name": "Aave", "tvl": 5200000000, "chains": ["Ethereum"]}
json
{"id": "2269", "name": "Aave", "tvl": 5200000000, "chains": ["Ethereum"]}

Price Response

价格返回

json
{"coins": {"ethereum:0x...": {"price": 0.999, "symbol": "USDC", "confidence": 0.99}}}
json
{"coins": {"ethereum:0x...": {"price": 0.999, "symbol": "USDC", "confidence": 0.99}}}

Yield Pool Response

收益池返回

json
{"pool": "uuid", "chain": "Ethereum", "project": "aave-v3", "apy": 3.5, "tvlUsd": 1500000000}
json
{"pool": "uuid", "chain": "Ethereum", "project": "aave-v3", "apy": 3.5, "tvlUsd": 1500000000}

GF(3) Integration

GF(3) 集成

This skill serves as MINUS (-1) validator in triads:
  • Provides authoritative DeFi data
  • Validates protocol metrics
  • Constrains analysis with real data
Compose with:
  • aptos-agent
    (+1): Execute based on data
  • exa-search
    (0): Enrich with web context
该技能在三元组中作为MINUS (-1) 验证器:
  • 提供权威DeFi数据
  • 验证协议指标
  • 用真实数据约束分析
可搭配以下技能使用:
  • aptos-agent
    (+1): 基于数据执行操作
  • exa-search
    (0): 用网页上下文丰富数据

Output Format Guidelines (Chinese/English Queries)

输出格式指南(支持中/英文查询)

Always format DeFi data responses as human-readable markdown. Support both Chinese and English queries.
始终将DeFi数据返回为人类可读的markdown格式,支持中英文查询。

Number Formatting

数字格式化

  • TVL ≥ $1B →
    $X.XXB
    ; TVL ≥ $1M →
    $XXXM
  • APY →
    XX.X%
  • 24h changes →
    +X.X%
    or
    -X.X%
  • Always include units:
    $
    ,
    %
    ,
    B
    (billion),
    M
    (million)
  • TVL ≥ $1B → 格式为
    $X.XXB
    ;TVL ≥ $1M → 格式为
    $XXXM
  • APY → 格式为
    XX.X%
  • 24小时变动 → 格式为
    +X.X%
    -X.X%
  • 始终保留单位:
    $
    %
    B
    (十亿)、
    M
    (百万)

Recommended Output Templates

推荐输出模板

TVL Leaderboard:
markdown
| # | Protocol | TVL | Chains |
|---|--------------|-----|-----------|
| 1 | Aave V3      | $24.7B | Ethereum, Arbitrum |
Yield Pools:
markdown
| Pool | APY | TVL | Risk |
|---------|-----|-----|---------|
| USDC    | 5.2% | $500M | ✅ Low risk |
Market Snapshot:
markdown
| Metric | Value |
|------------|-----------|
| Total TVL       | $96B       |
| DEX 24h volume  | $5.7B      |
| Fees 24h        | $49M       |
TVL排行榜:
markdown
| # | 协议 | TVL | 部署公链 |
|---|--------------|-----|-----------|
| 1 | Aave V3      | $24.7B | Ethereum, Arbitrum |
收益池:
markdown
| 收益池 | APY | TVL | 风险等级 |
|---------|-----|-----|---------|
| USDC    | 5.2% | $500M | ✅ 低风险 |
市场快照:
markdown
| 指标 | 数值 |
|------------|-----------|
| 总TVL       | $96B       |
| DEX 24小时交易量  | $5.7B      |
| 24小时总手续费        | $49M       |

Risk Labels

风险标签

Always include risk indicators for yield pools:
  • ✅ Low risk
    — stable APY < 20%, no IL risk
  • ⚠️ Medium risk
    — APY 20-100%, or IL risk present
  • 🔴 High risk
    — APY > 100% (likely incentive-driven, unsustainable)
收益池返回必须包含风险标识:
  • ✅ 低风险
    — 稳定APY < 20%,无常损失风险
  • ⚠️ 中风险
    — APY 20-100%,或存在无常损失风险
  • 🔴 高风险
    — APY > 100%(通常为激励驱动,不可持续)

Tip: excludeChart Parameter

提示:excludeChart参数

For volume/fee overview endpoints, always add
?excludeChart=true
to reduce response size:
bash
GET /overview/dexs?excludeChart=true    # DEX volumes (much faster)
GET /overview/fees?excludeChart=true    # Fee data (much faster)
查询交易量/手续费概览端点时,始终添加
?excludeChart=true
以减少返回体积:
bash
GET /overview/dexs?excludeChart=true    # DEX交易量(响应速度快很多)
GET /overview/fees?excludeChart=true    # 手续费数据(响应速度快很多)

Common Pitfalls & Gotchas

常见陷阱与注意事项

1. Wrong Base URL for Free Endpoints

1. 免费端点用错基础URL

❌ WRONG:
https://pro-api.llama.fi/protocols
→ returns 404 "Path needs to start with /yields/..." ✅ CORRECT:
https://api.llama.fi/protocols
Free endpoints NEVER go through
pro-api.llama.fi
.
❌ 错误:
https://pro-api.llama.fi/protocols
→ 返回404 "Path needs to start with /yields/..." ✅ 正确:
https://api.llama.fi/protocols
免费端点永远不会
pro-api.llama.fi
域名。

2. Pro Endpoint Without API Key

2. 专业版端点未带API密钥

❌ WRONG:
https://pro-api.llama.fi/yields/pools
→ 401 or wrong route ✅ CORRECT:
https://pro-api.llama.fi/{DEFILLAMA_API_KEY}/yields/pools
The API key is in the URL path, not in a header.
❌ 错误:
https://pro-api.llama.fi/yields/pools
→ 返回401或路由错误 ✅ 正确:
https://pro-api.llama.fi/{DEFILLAMA_API_KEY}/yields/pools
API密钥放在URL路径中,不是请求头里。

3. Missing
excludeChart=true
for Volume/Fee Endpoints

3. 交易量/手续费端点未加
excludeChart=true

Without this param,
/overview/dexs
returns large chart history arrays. Always add
?excludeChart=true
for summary queries.
不带该参数时,
/overview/dexs
会返回大量历史图表数组,汇总查询时请始终添加
?excludeChart=true

4. Handling TVL Null Values

4. 处理TVL空值

When sorting protocols by TVL, filter first:
python
valid = [p for p in protocols if isinstance(p.get('tvl'), (int, float)) and p['tvl'] > 0]
按TVL排序协议时,请先过滤无效值:
python
valid = [p for p in protocols if isinstance(p.get('tvl'), (int, float)) and p['tvl'] > 0]

5. Stablecoins vs TVL

5. 稳定币与TVL的区别

DefiLlama's chain TVL includes ALL DeFi assets, not just stablecoins. For stablecoin-specific flows, use the
stablecoins.llama.fi
API (separate from pro-api). When asked about "stablecoin flows", the chain TVL change is a reasonable proxy.
DefiLlama的公链TVL包含所有DeFi资产,不止稳定币。如果需要稳定币专属流量数据,请使用
stablecoins.llama.fi
API(与专业版API独立)。当用户询问“稳定币流量”时,公链TVL变化是合理的近似指标。

6. Yields Pool UUID

6. 收益池UUID

The
pool
field in
/yields/pools
is a UUID like
"747c1d2a-c668-4682-b9f9-296708a3dd90"
. Use this UUID (not token address) for
/yields/chart/{pool}
history.
/yields/pools
返回的
pool
字段是UUID,例如
"747c1d2a-c668-4682-b9f9-296708a3dd90"
。查询
/yields/chart/{pool}
历史数据时请使用该UUID(不是代币地址)。

7. Stablecoin Yield Screening Baseline

7. 稳定币收益筛选基准

For “conservative stablecoin yield” requests, start with this baseline filter:
  • stablecoin == true
  • tvlUsd >= 50_000_000
  • apy
    between
    2
    and
    20
    (drop extreme incentive spikes)
  • ilRisk == "no"
  • Prefer
    exposure == "single"
    for conservative profiles
当用户请求“稳健稳定币收益”时,可使用以下基准过滤:
  • stablecoin == true
  • tvlUsd >= 50_000_000
  • apy
    介于
    2
    20
    之间(排除极端激励波动)
  • ilRisk == "no"
  • 稳健型需求优先选择
    exposure == "single"
    的单资产池子

Workflow Examples (Agent Recipes)

工作流示例(Agent 方案)

Recipe 1: DeFi TVL Top 10 (1 call)

方案1: DeFi TVL Top10(1次请求)

python
r = requests.get("https://api.llama.fi/protocols")
protocols = r.json()
top10 = sorted([p for p in protocols if p.get('tvl',0) > 0], key=lambda x: x['tvl'], reverse=True)[:10]
python
r = requests.get("https://api.llama.fi/protocols")
protocols = r.json()
top10 = sorted([p for p in protocols if p.get('tvl',0) > 0], key=lambda x: x['tvl'], reverse=True)[:10]

Output: markdown table with | # | Protocol | TVL | Chain |

Output: markdown table with | # | Protocol | TVL | Chain |

undefined
undefined

Recipe 2: ETH vs SOL 30-day TVL comparison (2 calls)

方案2: ETH vs SOL 30天TVL对比(2次请求)

python
r1 = requests.get("https://api.llama.fi/v2/historicalChainTvl/Ethereum")
r2 = requests.get("https://api.llama.fi/v2/historicalChainTvl/Solana")
python
r1 = requests.get("https://api.llama.fi/v2/historicalChainTvl/Ethereum")
r2 = requests.get("https://api.llama.fi/v2/historicalChainTvl/Solana")

Filter last 30d: [d for d in r1.json() if d['date'] >= time.time() - 30*86400]

Filter last 30d: [d for d in r1.json() if d['date'] >= time.time() - 30*86400]

Output: | Chain | TVL 30d ago | TVL today | Change % |

Output: | Chain | TVL 30d ago | TVL today | Change % |

undefined
undefined

Recipe 3: Stablecoin yield shortlist (1 call)

方案3: 稳定币收益候选列表(1次请求)

python
r = requests.get(f"https://pro-api.llama.fi/{API_KEY}/yields/pools")
raw = r.json()
pools = raw.get('data', raw) if isinstance(raw, dict) else raw
safe = [p for p in pools
        if p.get('stablecoin') is True
        and (p.get('tvlUsd') or 0) >= 50_000_000
        and (p.get('apy') or 0) >= 2
        and (p.get('apy') or 0) <= 20
        and p.get('ilRisk') == 'no']
top = sorted(safe, key=lambda x: x.get('apy', 0), reverse=True)[:10]
python
r = requests.get(f"https://pro-api.llama.fi/{API_KEY}/yields/pools")
raw = r.json()
pools = raw.get('data', raw) if isinstance(raw, dict) else raw
safe = [p for p in pools
        if p.get('stablecoin') is True
        and (p.get('tvlUsd') or 0) >= 50_000_000
        and (p.get('apy') or 0) >= 2
        and (p.get('apy') or 0) <= 20
        and p.get('ilRisk') == 'no']
top = sorted(safe, key=lambda x: x.get('apy', 0), reverse=True)[:10]

Output: | Project | Chain | Symbol | APY | TVL | Risk |

Output: | Project | Chain | Symbol | APY | TVL | Risk |

undefined
undefined

Recipe 4: DeFi Market Snapshot (3 calls)

方案4: DeFi市场快照(3次请求)

python
chains = requests.get("https://api.llama.fi/v2/chains").json()
dexs   = requests.get("https://api.llama.fi/overview/dexs?excludeChart=true").json()
fees   = requests.get("https://api.llama.fi/overview/fees?excludeChart=true").json()
python
chains = requests.get("https://api.llama.fi/v2/chains").json()
dexs   = requests.get("https://api.llama.fi/overview/dexs?excludeChart=true").json()
fees   = requests.get("https://api.llama.fi/overview/fees?excludeChart=true").json()

total_tvl = sum(c['tvl'] for c in chains if isinstance(c.get('tvl'), (int,float)))

total_tvl = sum(c['tvl'] for c in chains if isinstance(c.get('tvl'), (int,float)))

Output: snapshot table with TVL, DEX 24h vol, Fee 24h

Output: snapshot table with TVL, DEX 24h vol, Fee 24h

undefined
undefined

Recipe 5: Protocol TVL spike analysis (2 calls)

方案5: 协议TVL异动分析(2次请求)

python
r1 = requests.get("https://api.llama.fi/protocols")  # find protocol with big change_1d
r2 = requests.get(f"https://api.llama.fi/protocol/{slug}")  # get chainTvls detail
python
r1 = requests.get("https://api.llama.fi/protocols")  # find protocol with big change_1d
r2 = requests.get(f"https://api.llama.fi/protocol/{slug}")  # get chainTvls detail

Output: | Hypothesis | Explanation | How to verify | (table + step-by-step verification)

Output: | Hypothesis | Explanation | How to verify | (table + step-by-step verification)

undefined
undefined

Stablecoin Data

稳定币数据

For stablecoin-specific analytics (distinct from general TVL), use the stablecoins API:
bash
undefined
如果需要稳定币专属分析(与通用TVL区分),请使用稳定币API:
bash
undefined

Stablecoins overview (separate from pro-api)

稳定币概览(与专业版API独立)

Chain-specific stablecoin data

单公链稳定币数据

chain = "Ethereum", "Solana", "BSC", etc.

chain可选值: "Ethereum", "Solana", "BSC", 等.

All chains stablecoin summary

所有公链稳定币汇总


When users ask about "stablecoin net flows" or "stablecoin inflows":
1. Use `stablecoincharts/{chain}` for 30-day stablecoin TVL change (more accurate than general TVL)
2. Or use `/v2/historicalChainTvl/{chain}` as proxy if stablecoin API is unavailable

当用户询问“稳定币净流量”或“稳定币流入”时:
1. 优先使用`stablecoincharts/{chain}`获取30天稳定币TVL变化(比通用TVL更准确)
2. 如果稳定币API不可用,可使用`/v2/historicalChainTvl/{chain}`作为近似指标

Yields Pool Data Handling

收益池数据处理

The
/yields/pools
response is
{"data": [...], "status": "success"}
:
python
r = session.get(f"https://pro-api.llama.fi/{api_key}/yields/pools")
raw = r.json()
pools = raw.get('data', raw) if isinstance(raw, dict) else raw
/yields/pools
返回格式为
{"data": [...], "status": "success"}
python
r = session.get(f"https://pro-api.llama.fi/{api_key}/yields/pools")
raw = r.json()
pools = raw.get('data', raw) if isinstance(raw, dict) else raw

Filter example: TVL > $50M and APY > 0

过滤示例: TVL > $50M 且 APY > 0

filtered = [p for p in pools if p.get('tvlUsd', 0) >= 50_000_000 and (p.get('apy') or 0) > 0]

**Key pool fields**:
| Field | Type | Description |
|-------|------|-------------|
| `pool` | UUID string | Unique pool identifier |
| `chain` | string | Chain name |
| `project` | string | Protocol name |
| `symbol` | string | Token pair (e.g. "USDC-WETH") |
| `tvlUsd` | number | TVL in USD |
| `apy` | number | Current APY % |
| `apyBase` | number | Base APY (lending/trading fees) |
| `apyReward` | number | Incentive APY (token rewards) |
| `ilRisk` | "yes"/"no" | Impermanent loss risk |
| `exposure` | "single"/"multi" | Single vs multi-asset exposure |
| `apyPct7D` | number | APY change past 7 days |
filtered = [p for p in pools if p.get('tvlUsd', 0) >= 50_000_000 and (p.get('apy') or 0) > 0]

**核心收益池字段**:
| 字段 | 类型 | 说明 |
|-------|------|-------------|
| `pool` | UUID字符串 | 收益池唯一标识 |
| `chain` | 字符串 | 部署公链名称 |
| `project` | 字符串 | 协议名称 |
| `symbol` | 字符串 | 代币对(例如 "USDC-WETH") |
| `tvlUsd` | 数字 | TVL(美元计价) |
| `apy` | 数字 | 当前APY % |
| `apyBase` | 数字 | 基础APY(借贷/交易手续费产生) |
| `apyReward` | 数字 | 激励APY(代币奖励产生) |
| `ilRisk` | "yes"/"no" | 是否存在无常损失风险 |
| `exposure` | "single"/"multi" | 单资产/多资产敞口 |
| `apyPct7D` | 数字 | 过去7天APY变动 |