mcpField
D
defillama-api

defillama-api

github.com/agiprolabs数据与数据库456451 次安装8 周前更新
代码仓库

关于 defillama-api

defillama-api 是使用 DeFiLlama API 进行 DeFi 数据分析的参考技能,适合查询协议和链上指标。它涵盖 TVL、代币价格、DEX 交易量、费用、稳定币及桥接列表,并提供多种无需认证的端点用法。

主要功能

  1. 01协议 TVL 和历史数据
  2. 02当前及历史代币价格
  3. 03DEX 交易量与费用概览
  4. 04稳定币供应数据
  5. 05桥接列表

适用场景

  1. 01比较不同链上的协议 TVL
  2. 02批量查询多个代币价格
  3. 03查看各链 DeFi 活动

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/agiprolabs/claude-trading-skills --skill defillama-api

安装后在 Claude Code 中输入/defillama-api确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

references/
coin_identifiers.md
endpoints.md
error_handling.md
scripts/
defi_snapshot.py
price_lookup.py

详细介绍

DeFiLlama API — DeFi 宏观分析

DeFiLlama 是最大的 DeFi TVL 聚合平台。大多数端点的 API 免费且无需身份验证,涵盖所有链上的 TVL、代币价格、DEX 交易量、费用/收入、稳定币和桥接数据。

快速入门

import httpx

# No auth required for free endpoints
BASE = "https://api.llama.fi"
COINS = "https://coins.llama.fi"

# Current TVL for a protocol
tvl = httpx.get(f"{BASE}/tvl/raydium").json()
print(f"Raydium TVL: ${tvl:,.0f}")

# Token prices (multi-chain)
resp = httpx.get(f"{COINS}/prices/current/solana:So11111111111111111111111111111111111111112")
sol_price = resp.json()["coins"]["solana:So11111111111111111111111111111111111111112"]["price"]

基础 URL

服务基础 URL身份验证
TVL / 协议https://api.llama.fi免费
Coin Priceshttps://coins.llama.fi免费
稳定币https://stablecoins.llama.fi免费
收益率https://yields.llama.fiPro($300/月)
桥接https://bridges.llama.fi免费(列表)/ Pro(详情)
Pro APIhttps://pro-api.llama.fi/{KEY}/api/...URL 路径中包含 Pro 密钥

速率限制:免费版约为每 5 分钟 500 个请求。Pro:每分钟 1,000 个请求,每月 100 万次调用。

TVL 和协议数据

# List all protocols with TVL
GET /protocols
# Returns: [{name, slug, tvl, chainTvls, change_1h, change_1d, change_7d, category, chains, ...}]

# Detailed protocol data with historical TVL
GET /protocol/{slug}
# Returns: Full object with tvl[], tokensInUsd{}, currentChainTvls{}, ...

# Simple current TVL number
GET /tvl/{slug}
# Returns: plain number (e.g., 150977324562.40)

# TVL for all chains
GET /v2/chains
# Returns: [{name, tvl, tokenSymbol, chainId, gecko_id}]

# Historical chain TVL
GET /v2/historicalChainTvl/{chain}
# chain: "Ethereum", "Solana", "Arbitrum", etc.
# Returns: [{date, tvl}] — date is unix timestamp (seconds)

代币价格

Coin 标识符使用 {chain}:{address} 格式:

  • solana:So11111111111111111111111111111111111111112(SOL)
  • ethereum:0xdac17f958d2ee523a2206206994597c13d831ec7(USDT)
  • coingecko:bitcoin(非链上查询)
# Current prices (batch)
GET /prices/current/{coins}
# coins: comma-separated identifiers
# Optional: searchWidth (default 4h)
# Returns: {coins: {id: {price, decimals, symbol, timestamp, confidence}}}

# Historical price at timestamp
GET /prices/historical/{timestamp}/{coins}
# timestamp: unix seconds

# Price chart
GET /chart/{coins}?period=1d&span=30
# period: 1d, 4h, 1h
# Returns: {coins: {id: {prices: [{timestamp, price}]}}}

# Price change percentage
GET /percentage/{coins}

# First recorded price
GET /prices/first/{coins}

# Block number at timestamp
GET /block/{chain}/{timestamp}
批量历史价格
# POST for multiple timestamps per coin
POST /batchHistorical
Body: {"coins": {"solana:So11...": [1709251200, 1709337600]}}

DEX 交易量

# All DEXes aggregated
GET /overview/dexs
# Optional: excludeTotalDataChart=true, dataType=dailyVolume

# Chain-specific
GET /overview/dexs/{chain}
# chain: "Solana", "Ethereum", etc.

# Specific DEX
GET /summary/dexs/{protocol}
# Returns: {total24h, total7d, total30d, totalAllTime, totalDataChart, ...}

费用和收入

# All protocols
GET /overview/fees
# Optional: dataType=dailyFees|dailyRevenue|dailyUserFees

# Chain-specific
GET /overview/fees/{chain}

# Specific protocol
GET /summary/fees/{protocol}
# Returns: {total24h, total7d, methodology{}, totalDataChart[], ...}

稳定币

# All stablecoins with supply data
GET https://stablecoins.llama.fi/stablecoins
# Returns: [{name, symbol, pegType, circulating, chainCirculating, price}]

# Historical market cap
GET https://stablecoins.llama.fi/stablecoincharts/all

# Chain-specific stablecoin data
GET https://stablecoins.llama.fi/stablecoincharts/{chain}

# Stablecoin prices (deviation tracking)
GET https://stablecoins.llama.fi/stablecoinprices

桥接

# List all bridges
GET https://bridges.llama.fi/bridges
# Optional: includeChains=true
# Returns: {bridges: [{name, volume stats, chains, ...}]}

常见模式

协议 TVL 对比
def compare_protocol_tvl(slugs: list[str]) -> list[dict]:
    """Compare TVL across protocols."""
    results = []
    for slug in slugs:
        resp = httpx.get(f"https://api.llama.fi/tvl/{slug}", timeout=15.0)
        if resp.status_code == 200:
            results.append({"protocol": slug, "tvl": resp.json()})
    return sorted(results, key=lambda x: x["tvl"], reverse=True)
多代币价格查询
def get_solana_prices(mints: list[str]) -> dict[str, float]:
    """Get USD prices for Solana tokens via DeFiLlama."""
    coins = ",".join(f"solana:{m}" for m in mints)
    resp = httpx.get(f"https://coins.llama.fi/prices/current/{coins}")
    data = resp.json().get("coins", {})
    return {
        mint: data[f"solana:{mint}"]["price"]
        for mint in mints
        if f"solana:{mint}" in data
    }
Solana DeFi 概览
def solana_defi_snapshot() -> dict:
    """Get a snapshot of Solana DeFi activity."""
    chain_tvl = httpx.get("https://api.llama.fi/v2/chains").json()
    sol_tvl = next((c["tvl"] for c in chain_tvl if c["name"] == "Solana"), 0)

    dex_vol = httpx.get("https://api.llama.fi/overview/dexs/Solana").json()
    fees = httpx.get("https://api.llama.fi/overview/fees/Solana").json()

    return {
        "tvl": sol_tvl,
        "dex_volume_24h": dex_vol.get("total24h", 0),
        "fees_24h": fees.get("total24h", 0),
    }
历史价格分析
def price_at_date(coin: str, date_str: str) -> float:
    """Get token price at a specific date.

    Args:
        coin: DeFiLlama coin ID (e.g., 'solana:So11...')
        date_str: Date string 'YYYY-MM-DD'
    """
    from datetime import datetime, timezone
    dt = datetime.strptime(date_str, "%Y-%m-%d").replace(tzinfo=timezone.utc)
    ts = int(dt.timestamp())
    resp = httpx.get(f"https://coins.llama.fi/prices/historical/{ts}/{coin}")
    data = resp.json().get("coins", {})
    return data.get(coin, {}).get("price", 0)

免费版与 Pro 端点

类别免费版Pro($300/月)
TVL / 协议是是
Coin Prices是是
DEX 交易量(概览)是是
费用/收入(概览)是是
稳定币是是
桥接(列表)是是
收益率 / 池否是
桥接详情否是
衍生品否是
排放/解锁否是
金库否是
黑客攻击数据库否是

何时选择 DeFiLlama 而非其他方案

需求使用
协议 TVL 对比DeFiLlama
多链代币价格DeFiLlama(免费批量查询)
特定时间戳的历史价格DeFiLlama
DeFi 宏观分析DeFiLlama
Solana 代币 OHLCVBirdeye 或 SolanaTracker
实时代币数据DexScreener 或 Birdeye
钱包 PnLSolanaTracker
链上交易数据Helius

文件

参考资料
  • references/endpoints.md — 完整端点列表,包含参数和响应架构
  • references/coin_identifiers.md — 链前缀、地址格式和批量查询模式
  • references/error_handling.md — 速率限制、错误代码、重试策略和大型响应处理
脚本
  • scripts/defi_snapshot.py — Solana DeFi 概览:TVL、交易量、费用和顶级协议
  • scripts/price_lookup.py — 多代币价格查询和历史对比

评论

支持 Markdown