tracking-crypto-prices

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Tracking Crypto Prices

加密货币价格追踪

Overview

概述

Foundation skill providing real-time and historical cryptocurrency price data. This skill is the data layer for the crypto plugin ecosystem - 10+ other skills depend on it for price information.
Key Capabilities:
  • Real-time prices for 10,000+ cryptocurrencies
  • Historical OHLCV data (1 day to all-time)
  • Multi-currency support (USD, EUR, GBP, 30+ currencies)
  • Intelligent caching to minimize API calls
  • Predefined and custom watchlists
  • Export to CSV/JSON for analysis
Dependent Skills: This skill provides price data to: market-movers-scanner, crypto-portfolio-tracker, crypto-tax-calculator, defi-yield-optimizer, liquidity-pool-analyzer, staking-rewards-optimizer, crypto-derivatives-tracker, dex-aggregator-router, options-flow-analyzer, arbitrage-opportunity-finder.
作为基础技能,提供实时与历史加密货币价格数据。该技能是加密货币插件生态的数据层——有10余个其他技能依赖其获取价格信息。
核心功能:
  • 支持10000+种加密货币的实时价格查询
  • 历史OHLCV数据(1天至全时段)
  • 多法币支持(USD、EUR、GBP等30余种货币)
  • 智能缓存,减少API调用次数
  • 预定义与自定义关注列表
  • 导出为CSV/JSON格式用于分析
依赖该技能的其他技能: 本技能为以下技能提供价格数据:market-movers-scanner、crypto-portfolio-tracker、crypto-tax-calculator、defi-yield-optimizer、liquidity-pool-analyzer、staking-rewards-optimizer、crypto-derivatives-tracker、dex-aggregator-router、options-flow-analyzer、arbitrage-opportunity-finder。

Prerequisites

前置条件

Install required dependencies:
bash
pip install requests pandas yfinance
Optional for advanced features:
bash
pip install python-dotenv  # For API key management
API Setup (optional, for higher rate limits):
  1. Get free API key from https://www.coingecko.com/en/api
  2. Add to
    {baseDir}/config/settings.yaml
    or set environment variable
    COINGECKO_API_KEY
安装所需依赖:
bash
pip install requests pandas yfinance
高级功能可选依赖:
bash
pip install python-dotenv  # 用于API密钥管理
API设置(可选,用于更高调用限额):
  1. https://www.coingecko.com/en/api获取免费API密钥
  2. 添加至
    {baseDir}/config/settings.yaml
    或设置环境变量
    COINGECKO_API_KEY

Instructions

使用说明

Step 1: Quick Price Check

步骤1:快速价格查询

Get current price for any cryptocurrency:
bash
python {baseDir}/scripts/price_tracker.py --symbol BTC
Check multiple assets:
bash
python {baseDir}/scripts/price_tracker.py --symbols BTC,ETH,SOL
获取任意加密货币的当前价格:
bash
python {baseDir}/scripts/price_tracker.py --symbol BTC
查询多个资产:
bash
python {baseDir}/scripts/price_tracker.py --symbols BTC,ETH,SOL

Step 2: Use Watchlists

步骤2:使用关注列表

Scan predefined watchlists:
bash
undefined
扫描预定义关注列表:
bash
undefined

Top 10 by market cap

市值前10币种

python {baseDir}/scripts/price_tracker.py --watchlist top10
python {baseDir}/scripts/price_tracker.py --watchlist top10

DeFi tokens

DeFi代币

python {baseDir}/scripts/price_tracker.py --watchlist defi
python {baseDir}/scripts/price_tracker.py --watchlist defi

Layer 2 tokens

Layer2代币

python {baseDir}/scripts/price_tracker.py --watchlist layer2

Available watchlists: `top10`, `defi`, `layer2`, `stablecoins`, `memecoins`
python {baseDir}/scripts/price_tracker.py --watchlist layer2

可用关注列表:`top10`、`defi`、`layer2`、`stablecoins`、`memecoins`

Step 3: Fetch Historical Data

步骤3:获取历史数据

Get OHLCV (Open, High, Low, Close, Volume) history:
bash
undefined
获取OHLCV(开盘、最高、最低、收盘、成交量)历史数据:
bash
undefined

Last 30 days

最近30天数据

python {baseDir}/scripts/price_tracker.py --symbol BTC --period 30d
python {baseDir}/scripts/price_tracker.py --symbol BTC --period 30d

Last 90 days with CSV export

最近90天数据并导出为CSV

python {baseDir}/scripts/price_tracker.py --symbol BTC --period 90d --output csv
python {baseDir}/scripts/price_tracker.py --symbol BTC --period 90d --output csv

Custom date range

自定义日期范围

python {baseDir}/scripts/price_tracker.py --symbol ETH --start 2024-01-01 --end 2024-12-31
undefined
python {baseDir}/scripts/price_tracker.py --symbol ETH --start 2024-01-01 --end 2024-12-31
undefined

Step 4: Configure Settings

步骤4:配置设置

Edit
{baseDir}/config/settings.yaml
to customize:
yaml
cache:
  spot_ttl: 30          # Seconds to cache spot prices
  historical_ttl: 3600  # Seconds to cache historical data

currency:
  default: usd          # Default fiat currency

watchlists:
  custom:               # Add your own watchlist
    - BTC
    - ETH
    - SOL
编辑
{baseDir}/config/settings.yaml
进行自定义配置:
yaml
cache:
  spot_ttl: 30          # 现货价格缓存有效期(秒)
  historical_ttl: 3600  # 历史数据缓存有效期(秒)

currency:
  default: usd          # 默认法币

watchlists:
  custom:               # 添加自定义关注列表
    - BTC
    - ETH
    - SOL

Output

输出格式

Price Table (Default)

价格表格(默认)

================================================================================
  CRYPTO PRICES                                           Updated: [timestamp]
================================================================================

  Symbol     Price (USD)      24h Change     Volume (24h)      Market Cap
--------------------------------------------------------------------------------
  BTC       $97,234.56          +2.34%      $28.5B            $1.92T
  ETH        $3,456.78          +1.87%      $12.3B            $415.2B
  SOL          $142.34          +5.12%       $2.1B             $61.4B
--------------------------------------------------------------------------------

  Total 24h Change: +2.44% (weighted)

================================================================================
================================================================================
  CRYPTO PRICES                                           Updated: [timestamp]
================================================================================

  Symbol     Price (USD)      24h Change     Volume (24h)      Market Cap
--------------------------------------------------------------------------------
  BTC       $97,234.56          +2.34%      $28.5B            $1.92T
  ETH        $3,456.78          +1.87%      $12.3B            $415.2B
  SOL          $142.34          +5.12%       $2.1B             $61.4B
--------------------------------------------------------------------------------

  Total 24h Change: +2.44% (weighted)

================================================================================

JSON Output (--format json)

JSON输出(--format json)

json
{
  "prices": [
    {
      "symbol": "BTC",
      "name": "Bitcoin",
      "price": 97234.56,
      "currency": "USD",
      "change_24h": 2.34,
      "volume_24h": 28500000000,
      "market_cap": 1920000000000,
      "timestamp": "[timestamp]",
      "source": "coingecko"
    }
  ],
  "meta": {
    "count": 1,
    "currency": "USD",
    "cached": false
  }
}
json
{
  "prices": [
    {
      "symbol": "BTC",
      "name": "Bitcoin",
      "price": 97234.56,
      "currency": "USD",
      "change_24h": 2.34,
      "volume_24h": 28500000000,
      "market_cap": 1920000000000,
      "timestamp": "[timestamp]",
      "source": "coingecko"
    }
  ],
  "meta": {
    "count": 1,
    "currency": "USD",
    "cached": false
  }
}

Historical CSV Export

历史数据CSV导出

csv
date,open,high,low,close,volume
[date],95000.00,96500.00,94200.00,96100.00,25000000000
[date],96100.00,97800.00,95800.00,97500.00,27000000000
csv
date,open,high,low,close,volume
[date],95000.00,96500.00,94200.00,96100.00,25000000000
[date],96100.00,97800.00,95800.00,97500.00,27000000000

Configuration

配置详情

Edit
{baseDir}/config/settings.yaml
:
yaml
undefined
编辑
{baseDir}/config/settings.yaml
yaml
undefined

API Configuration

API配置

api: coingecko: api_key: ${COINGECKO_API_KEY} # Optional, from env use_pro: false yfinance: enabled: true # Fallback source
api: coingecko: api_key: ${COINGECKO_API_KEY} # 可选,从环境变量读取 use_pro: false yfinance: enabled: true # 备选数据源

Cache Configuration

缓存配置

cache: enabled: true spot_ttl: 30 # Spot price TTL (seconds) historical_ttl: 3600 # Historical data TTL (seconds) directory: ./data
cache: enabled: true spot_ttl: 30 # 现货价格缓存有效期(秒) historical_ttl: 3600 # 历史数据缓存有效期(秒) directory: ./data

Display Configuration

显示配置

currency: default: usd supported: - usd - eur - gbp - jpy - cad - aud
currency: default: usd supported: - usd - eur - gbp - jpy - cad - aud

Predefined Watchlists

预定义关注列表

watchlists: top10: - bitcoin - ethereum - tether - binancecoin - solana - ripple - cardano - avalanche-2 - dogecoin - polkadot
defi: - uniswap - aave - chainlink - maker - compound-governance-token - curve-dao-token - sushi
layer2: - matic-network - arbitrum - optimism - immutable-x
undefined
watchlists: top10: - bitcoin - ethereum - tether - binancecoin - solana - ripple - cardano - avalanche-2 - dogecoin - polkadot
defi: - uniswap - aave - chainlink - maker - compound-governance-token - curve-dao-token - sushi
layer2: - matic-network - arbitrum - optimism - immutable-x
undefined

Error Handling

错误处理

See
{baseDir}/references/errors.md
for comprehensive error handling.
完整错误处理说明请查看
{baseDir}/references/errors.md

Common Errors

常见错误

ErrorCauseSolution
Unknown symbol: XYZ
Invalid cryptocurrency tickerCheck spelling, use
--list
to search
Rate limit exceeded
Too many API callsWait 60s, or use API key for higher limits
Network error
No internet connectionCheck connection, cached data will be used
Cache stale
Cached data older than TTLData still shown with warning, will refresh
错误信息原因解决方案
Unknown symbol: XYZ
加密货币代码无效检查拼写,使用
--list
命令搜索
Rate limit exceeded
API调用次数超限等待60秒,或使用API密钥提升限额
Network error
无网络连接检查网络,将使用缓存数据
Cache stale
缓存数据超出有效期仍会显示数据并附带提醒,将自动刷新

Rate Limit Handling

调用限额处理

The skill automatically:
  1. Uses cached data when available
  2. Applies exponential backoff on rate limits
  3. Falls back to yfinance if CoinGecko fails
  4. Shows stale cache data with warning as last resort
该技能会自动执行以下操作:
  1. 优先使用可用缓存数据
  2. 触发限额时应用指数退避策略
  3. 若CoinGecko失败,自动切换至yfinance作为备选
  4. 最后会显示过期缓存数据并附带提醒

Examples

使用示例

See
{baseDir}/references/examples.md
for detailed examples including:
  • Multi-timeframe analysis
  • Portfolio value calculation
  • Price alert setup
  • Integration with other skills
详细示例请查看
{baseDir}/references/examples.md
,包括:
  • 多时间框架分析
  • 投资组合价值计算
  • 价格提醒设置
  • 与其他技能集成

Example 1: Quick Price Check

示例1:快速价格查询

bash
python {baseDir}/scripts/price_tracker.py --symbol BTC
Output:
BTC (Bitcoin)
$97,234.56 USD
+2.34% (24h) | Vol: $28.5B | MCap: $1.92T
bash
python {baseDir}/scripts/price_tracker.py --symbol BTC
输出:
BTC (Bitcoin)
$97,234.56 USD
+2.34% (24h) | Vol: $28.5B | MCap: $1.92T

Example 2: Watchlist Scan

示例2:关注列表扫描

bash
python {baseDir}/scripts/price_tracker.py --watchlist top10
bash
python {baseDir}/scripts/price_tracker.py --watchlist top10

Example 3: Historical Export

示例3:历史数据导出

bash
python {baseDir}/scripts/price_tracker.py --symbol ETH --period 90d --output csv
Creates:
{baseDir}/data/ETH_90d_[date].csv
bash
python {baseDir}/scripts/price_tracker.py --symbol ETH --period 90d --output csv
生成文件:
{baseDir}/data/ETH_90d_[date].csv

Integration with Other Skills

与其他技能集成

This skill provides the price data foundation for other crypto skills.
Direct Import (recommended for Python skills):
python
from price_tracker import get_current_prices, get_historical_prices
该技能为其他加密货币相关技能提供价格数据基础。
直接导入(推荐Python技能使用):
python
from price_tracker import get_current_prices, get_historical_prices

Get prices for portfolio valuation

获取投资组合估值所需价格

prices = get_current_prices(["BTC", "ETH", "SOL"])

**CLI Subprocess** (for non-Python or isolation):
```bash
PRICES=$(python {baseDir}/scripts/price_tracker.py --symbols BTC,ETH --format json)
Shared Cache (efficient for batch): Multiple skills can read from
{baseDir}/data/cache.json
to avoid redundant API calls.
prices = get_current_prices(["BTC", "ETH", "SOL"])

**CLI子进程调用**(适用于非Python技能或隔离场景):
```bash
PRICES=$(python {baseDir}/scripts/price_tracker.py --symbols BTC,ETH --format json)
共享缓存(批量场景高效使用): 多个技能可读取
{baseDir}/data/cache.json
避免重复API调用。

Files

文件结构

FilePurpose
scripts/price_tracker.py
Main CLI entry point
scripts/api_client.py
CoinGecko/yfinance abstraction
scripts/cache_manager.py
Cache read/write/invalidation
scripts/formatters.py
Output formatting
config/settings.yaml
User configuration
data/cache.json
Price cache (auto-generated)
文件用途
scripts/price_tracker.py
主CLI入口
scripts/api_client.py
CoinGecko/yfinance抽象层
scripts/cache_manager.py
缓存读写与失效管理
scripts/formatters.py
输出格式处理
config/settings.yaml
用户配置文件
data/cache.json
价格缓存文件(自动生成)

Resources

参考资源

  • CoinGecko API - Primary data source
  • yfinance - Fallback for historical data
  • PRD.md - Product requirements
  • ARD.md - Architecture documentation
  • CoinGecko API - 主要数据源
  • yfinance - 历史数据备选源
  • PRD.md - 产品需求文档
  • ARD.md - 架构设计文档