cmc-api-crypto

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

CoinMarketCap Cryptocurrency API

CoinMarketCap加密货币API

This skill covers the CoinMarketCap Cryptocurrency API endpoints for retrieving price data, market listings, historical quotes, trending coins, and token metadata.
本技能涵盖CoinMarketCap加密货币API的各类端点,可用于获取价格数据、市场列表、历史报价、热门代币及代币元数据。

Authentication

认证

All requests require an API key in the header.
bash
curl -X GET "https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest" \
  -H "X-CMC_PRO_API_KEY: your-api-key"
所有请求都需要在请求头中携带API密钥。
bash
curl -X GET "https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest" \
  -H "X-CMC_PRO_API_KEY: your-api-key"
在此获取您的API密钥:https://pro.coinmarketcap.com/login

Base URL

基础URL

https://pro-api.coinmarketcap.com
https://pro-api.coinmarketcap.com

Common Use Cases

常见使用场景

See use-cases.md for goal-based guidance on which endpoint to use:
  1. Get current price of a token
  2. Find a token's CMC ID from symbol or name
  3. Get a token by contract address
  4. Get top 100 coins by market cap
  5. Find coins in a price range
  6. Get historical price at a specific date
  7. Build a price chart (OHLCV data)
  8. Find where a coin trades
  9. Get all-time high and distance from ATH
  10. Find today's biggest gainers
  11. Discover newly listed coins
  12. Get all tokens in a category (e.g., DeFi)
请查看use-cases.md获取基于目标的端点选择指南:
  1. 获取代币当前价格
  2. 通过符号或名称查找代币的CMC ID
  3. 通过合约地址获取代币信息
  4. 获取市值排名前100的代币
  5. 查找特定价格区间内的代币
  6. 获取特定日期的历史价格
  7. 构建价格图表(OHLCV数据)
  8. 查找代币的交易平台
  9. 获取历史最高价及与当前价格的差距
  10. 查找当日涨幅最大的代币
  11. 发现新上线的代币
  12. 获取某一分类下的所有代币(如DeFi)

API Overview

API概述

EndpointDescriptionReference
GET /v1/cryptocurrency/categoriesList all categories with market metricscategories.md
GET /v1/cryptocurrency/categorySingle category detailscategories.md
GET /v1/cryptocurrency/listings/historicalHistorical listings snapshotlistings.md
GET /v1/cryptocurrency/listings/latestCurrent listings with market datalistings.md
GET /v1/cryptocurrency/listings/newNewly added cryptocurrencieslistings.md
GET /v1/cryptocurrency/mapMap names/symbols to CMC IDsmap.md
GET /v1/cryptocurrency/trending/gainers-losersTop gainers and loserstrending.md
GET /v1/cryptocurrency/trending/latestCurrently trending coinstrending.md
GET /v1/cryptocurrency/trending/most-visitedMost visited on CMCtrending.md
GET /v2/cryptocurrency/infoStatic metadata (logo, description, URLs)info.md
GET /v2/cryptocurrency/market-pairs/latestTrading pairs for a coinmarket-pairs.md
GET /v2/cryptocurrency/ohlcv/historicalHistorical OHLCV candlesohlcv.md
GET /v2/cryptocurrency/ohlcv/latestLatest OHLCV dataohlcv.md
GET /v2/cryptocurrency/price-performance-stats/latestPrice performance statsprice-performance.md
GET /v2/cryptocurrency/quotes/latestLatest price quotesquotes.md
GET /v3/cryptocurrency/quotes/historicalHistorical price quotesquotes.md
端点描述参考
GET /v1/cryptocurrency/categories列出所有包含市场指标的分类categories.md
GET /v1/cryptocurrency/category获取单个分类的详细信息categories.md
GET /v1/cryptocurrency/listings/historical获取历史列表快照listings.md
GET /v1/cryptocurrency/listings/latest获取包含市场数据的当前列表listings.md
GET /v1/cryptocurrency/listings/new获取新添加的加密货币listings.md
GET /v1/cryptocurrency/map将名称/符号映射为CMC IDmap.md
GET /v1/cryptocurrency/trending/gainers-losers获取涨幅和跌幅最大的代币trending.md
GET /v1/cryptocurrency/trending/latest获取当前热门代币trending.md
GET /v1/cryptocurrency/trending/most-visited获取CMC上访问量最高的代币trending.md
GET /v2/cryptocurrency/info获取静态元数据(logo、描述、URL)info.md
GET /v2/cryptocurrency/market-pairs/latest获取代币的交易对信息market-pairs.md
GET /v2/cryptocurrency/ohlcv/historical获取历史OHLCV蜡烛图数据ohlcv.md
GET /v2/cryptocurrency/ohlcv/latest获取最新的OHLCV数据ohlcv.md
GET /v2/cryptocurrency/price-performance-stats/latest获取价格表现统计数据price-performance.md
GET /v2/cryptocurrency/quotes/latest获取最新价格报价quotes.md
GET /v3/cryptocurrency/quotes/historical获取历史价格报价quotes.md

Common Workflows

常见工作流

Get Token Price by Symbol

通过代币符号获取代币价格

  1. First, map the symbol to a CMC ID using
    /v1/cryptocurrency/map
  2. Then fetch the price using
    /v2/cryptocurrency/quotes/latest
bash
undefined
  1. 首先,使用
    /v1/cryptocurrency/map
    端点将符号映射为CMC ID
  2. 然后使用
    /v2/cryptocurrency/quotes/latest
    端点获取价格
bash
undefined

Step 1: Get CMC ID for ETH

步骤1:获取ETH的CMC ID

curl -X GET "https://pro-api.coinmarketcap.com/v1/cryptocurrency/map?symbol=ETH"
-H "X-CMC_PRO_API_KEY: your-api-key"
curl -X GET "https://pro-api.coinmarketcap.com/v1/cryptocurrency/map?symbol=ETH"
-H "X-CMC_PRO_API_KEY: your-api-key"

Step 2: Get price quote (using id=1027 for ETH)

步骤2:获取价格报价(使用ETH的ID=1027)

curl -X GET "https://pro-api.coinmarketcap.com/v2/cryptocurrency/quotes/latest?id=1027"
-H "X-CMC_PRO_API_KEY: your-api-key"
undefined
curl -X GET "https://pro-api.coinmarketcap.com/v2/cryptocurrency/quotes/latest?id=1027"
-H "X-CMC_PRO_API_KEY: your-api-key"
undefined

Get Top 100 Coins by Market Cap

获取市值排名前100的代币

bash
curl -X GET "https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest?limit=100&sort=market_cap" \
  -H "X-CMC_PRO_API_KEY: your-api-key"
bash
curl -X GET "https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest?limit=100&sort=market_cap" \
  -H "X-CMC_PRO_API_KEY: your-api-key"

Get Historical Price Data

获取历史价格数据

bash
curl -X GET "https://pro-api.coinmarketcap.com/v3/cryptocurrency/quotes/historical?id=1&time_start=2024-01-01&time_end=2024-01-31&interval=daily" \
  -H "X-CMC_PRO_API_KEY: your-api-key"
bash
curl -X GET "https://pro-api.coinmarketcap.com/v3/cryptocurrency/quotes/historical?id=1&time_start=2024-01-01&time_end=2024-01-31&interval=daily" \
  -H "X-CMC_PRO_API_KEY: your-api-key"

Get Token Metadata

获取代币元数据

bash
curl -X GET "https://pro-api.coinmarketcap.com/v2/cryptocurrency/info?id=1,1027" \
  -H "X-CMC_PRO_API_KEY: your-api-key"
bash
curl -X GET "https://pro-api.coinmarketcap.com/v2/cryptocurrency/info?id=1,1027" \
  -H "X-CMC_PRO_API_KEY: your-api-key"

Error Handling

错误处理

HTTP Status Codes

HTTP状态码

CodeMeaning
200Success
400Bad request (invalid parameters)
401Unauthorized (invalid API key)
403Forbidden (endpoint not available on your plan)
429Rate limit exceeded
500Server error
状态码含义
200请求成功
400无效请求(参数错误)
401未授权(API密钥无效)
403禁止访问(您的套餐无法使用该端点)
429请求速率超限
500服务器错误

Rate Limits

请求速率限制

Rate limits depend on your subscription plan. The response headers include:
  1. X-CMC_PRO_API_KEY_CREDITS_USED
    - Credits used this call
  2. X-CMC_PRO_API_KEY_CREDITS_LEFT
    - Credits remaining
请求速率限制取决于您的订阅套餐。响应头包含以下信息:
  1. X-CMC_PRO_API_KEY_CREDITS_USED
    - 本次调用消耗的积分
  2. X-CMC_PRO_API_KEY_CREDITS_LEFT
    - 剩余积分

Common Errors

常见错误

Invalid ID: Ensure you use valid CMC IDs from the
/map
endpoint. Symbol lookups may return multiple matches.
Missing Required Parameter: Some endpoints require at least one identifier (id, slug, or symbol).
Plan Restrictions: Historical endpoints and some features require paid plans. Check your plan limits.
无效ID:请确保使用从
/map
端点获取的有效CMC ID。通过符号查询可能返回多个匹配结果。
缺少必填参数:部分端点至少需要一个标识符(id、slug或symbol)。
套餐限制:历史数据端点和部分功能需要付费套餐。请查看您的套餐限制。

Error Response Format

错误响应格式

json
{
  "status": {
    "timestamp": "2024-01-15T12:00:00.000Z",
    "error_code": 400,
    "error_message": "Invalid value for 'id'",
    "credit_count": 0
  }
}
json
{
  "status": {
    "timestamp": "2024-01-15T12:00:00.000Z",
    "error_code": 400,
    "error_message": "Invalid value for 'id'",
    "credit_count": 0
  }
}

Response Format

响应格式

All responses follow this structure:
json
{
  "status": {
    "timestamp": "2024-01-15T12:00:00.000Z",
    "error_code": 0,
    "error_message": null,
    "credit_count": 1
  },
  "data": { ... }
}
所有响应均遵循以下结构:
json
{
  "status": {
    "timestamp": "2024-01-15T12:00:00.000Z",
    "error_code": 0,
    "error_message": null,
    "credit_count": 1
  },
  "data": { ... }
}

Reference Files

参考文件

See the
references/
directory for complete parameter and response documentation for each endpoint.
请查看
references/
目录获取每个端点的完整参数和响应文档。