cmc-api-crypto
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCoinMarketCap 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"Get your API key at: https://pro.coinmarketcap.com/login
所有请求都需要在请求头中携带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.comhttps://pro-api.coinmarketcap.comCommon Use Cases
常见使用场景
See use-cases.md for goal-based guidance on which endpoint to use:
- Get current price of a token
- Find a token's CMC ID from symbol or name
- Get a token by contract address
- Get top 100 coins by market cap
- Find coins in a price range
- Get historical price at a specific date
- Build a price chart (OHLCV data)
- Find where a coin trades
- Get all-time high and distance from ATH
- Find today's biggest gainers
- Discover newly listed coins
- Get all tokens in a category (e.g., DeFi)
请查看use-cases.md获取基于目标的端点选择指南:
- 获取代币当前价格
- 通过符号或名称查找代币的CMC ID
- 通过合约地址获取代币信息
- 获取市值排名前100的代币
- 查找特定价格区间内的代币
- 获取特定日期的历史价格
- 构建价格图表(OHLCV数据)
- 查找代币的交易平台
- 获取历史最高价及与当前价格的差距
- 查找当日涨幅最大的代币
- 发现新上线的代币
- 获取某一分类下的所有代币(如DeFi)
API Overview
API概述
| Endpoint | Description | Reference |
|---|---|---|
| GET /v1/cryptocurrency/categories | List all categories with market metrics | categories.md |
| GET /v1/cryptocurrency/category | Single category details | categories.md |
| GET /v1/cryptocurrency/listings/historical | Historical listings snapshot | listings.md |
| GET /v1/cryptocurrency/listings/latest | Current listings with market data | listings.md |
| GET /v1/cryptocurrency/listings/new | Newly added cryptocurrencies | listings.md |
| GET /v1/cryptocurrency/map | Map names/symbols to CMC IDs | map.md |
| GET /v1/cryptocurrency/trending/gainers-losers | Top gainers and losers | trending.md |
| GET /v1/cryptocurrency/trending/latest | Currently trending coins | trending.md |
| GET /v1/cryptocurrency/trending/most-visited | Most visited on CMC | trending.md |
| GET /v2/cryptocurrency/info | Static metadata (logo, description, URLs) | info.md |
| GET /v2/cryptocurrency/market-pairs/latest | Trading pairs for a coin | market-pairs.md |
| GET /v2/cryptocurrency/ohlcv/historical | Historical OHLCV candles | ohlcv.md |
| GET /v2/cryptocurrency/ohlcv/latest | Latest OHLCV data | ohlcv.md |
| GET /v2/cryptocurrency/price-performance-stats/latest | Price performance stats | price-performance.md |
| GET /v2/cryptocurrency/quotes/latest | Latest price quotes | quotes.md |
| GET /v3/cryptocurrency/quotes/historical | Historical price quotes | quotes.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 ID | map.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
通过代币符号获取代币价格
- First, map the symbol to a CMC ID using
/v1/cryptocurrency/map - Then fetch the price using
/v2/cryptocurrency/quotes/latest
bash
undefined- 首先,使用端点将符号映射为CMC ID
/v1/cryptocurrency/map - 然后使用端点获取价格
/v2/cryptocurrency/quotes/latest
bash
undefinedStep 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"
-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"
-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"
-H "X-CMC_PRO_API_KEY: your-api-key"
undefinedcurl -X GET "https://pro-api.coinmarketcap.com/v2/cryptocurrency/quotes/latest?id=1027"
-H "X-CMC_PRO_API_KEY: your-api-key"
-H "X-CMC_PRO_API_KEY: your-api-key"
undefinedGet 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状态码
| Code | Meaning |
|---|---|
| 200 | Success |
| 400 | Bad request (invalid parameters) |
| 401 | Unauthorized (invalid API key) |
| 403 | Forbidden (endpoint not available on your plan) |
| 429 | Rate limit exceeded |
| 500 | Server error |
| 状态码 | 含义 |
|---|---|
| 200 | 请求成功 |
| 400 | 无效请求(参数错误) |
| 401 | 未授权(API密钥无效) |
| 403 | 禁止访问(您的套餐无法使用该端点) |
| 429 | 请求速率超限 |
| 500 | 服务器错误 |
Rate Limits
请求速率限制
Rate limits depend on your subscription plan. The response headers include:
- - Credits used this call
X-CMC_PRO_API_KEY_CREDITS_USED - - Credits remaining
X-CMC_PRO_API_KEY_CREDITS_LEFT
请求速率限制取决于您的订阅套餐。响应头包含以下信息:
- - 本次调用消耗的积分
X-CMC_PRO_API_KEY_CREDITS_USED - - 剩余积分
X-CMC_PRO_API_KEY_CREDITS_LEFT
Common Errors
常见错误
Invalid ID: Ensure you use valid CMC IDs from the endpoint. Symbol lookups may return multiple matches.
/mapMissing 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:请确保使用从端点获取的有效CMC ID。通过符号查询可能返回多个匹配结果。
/map缺少必填参数:部分端点至少需要一个标识符(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 directory for complete parameter and response documentation for each endpoint.
references/请查看目录获取每个端点的完整参数和响应文档。
references/