tracking-crypto-portfolio
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTracking Crypto Portfolio
加密货币投资组合追踪
Overview
概述
This skill provides comprehensive cryptocurrency portfolio tracking with:
- Real-Time Valuations: Current prices from CoinGecko
- Holdings Breakdown: Quantity, value, and allocation per asset
- P&L Tracking: Unrealized gains/losses with cost basis
- Allocation Analysis: Category breakdown and concentration flags
- Multiple Export Formats: Table, JSON, CSV
Key Capabilities:
- Track holdings across multiple assets
- Calculate portfolio total value in USD
- Identify overweight positions (concentration risk)
- Export for analysis tools and tax reporting
该工具提供全面的加密货币投资组合追踪功能,包括:
- 实时估值:来自CoinGecko的当前价格
- 持仓明细:单资产的数量、价值和配置占比
- 盈亏追踪:基于成本价的未实现盈亏
- 配置分析:品类细分和集中度标记
- 多种导出格式:表格、JSON、CSV
核心功能:
- 追踪多资产持仓情况
- 以美元计算投资组合总价值
- 识别超配头寸(集中度风险)
- 导出数据至分析工具和税务报告系统
Prerequisites
前提条件
Before using this skill, ensure:
- Python 3.8+ is installed
- requests library is available:
pip install requests - Internet connectivity for CoinGecko API access
- A portfolio JSON file with your holdings
使用本工具前,请确保:
- 已安装 Python 3.8+
- 已安装 requests 库:
pip install requests - 具备网络连接以访问CoinGecko API
- 拥有包含您持仓信息的投资组合JSON文件
Portfolio File Format
投资组合文件格式
Create a portfolio file (e.g., ):
holdings.jsonjson
{
"name": "My Portfolio",
"holdings": [
{"coin": "BTC", "quantity": 0.5, "cost_basis": 25000},
{"coin": "ETH", "quantity": 10, "cost_basis": 2000},
{"coin": "SOL", "quantity": 100}
]
}Fields:
- : Symbol (BTC, ETH, etc.) - required
coin - : Amount held - required
quantity - : Average purchase price per coin (optional, for P&L)
cost_basis - : Date acquired (optional, for records)
acquired
创建投资组合文件(例如 ):
holdings.jsonjson
{
"name": "My Portfolio",
"holdings": [
{"coin": "BTC", "quantity": 0.5, "cost_basis": 25000},
{"coin": "ETH", "quantity": 10, "cost_basis": 2000},
{"coin": "SOL", "quantity": 100}
]
}字段说明:
- :代币符号(BTC、ETH等)- 必填
coin - :持有数量 - 必填
quantity - :单币平均买入价(可选,用于计算盈亏)
cost_basis - :买入日期(可选,用于记录)
acquired
Instructions
使用说明
Step 1: Assess User Intent
步骤1:评估用户需求
Determine what portfolio information the user needs:
- Quick check: Total value and top holdings
- Holdings list: Full breakdown of all positions
- Detailed analysis: Allocations, P&L, risk flags
- Export: JSON or CSV for external tools
确定用户需要的投资组合信息类型:
- 快速查看:总价值和顶级持仓
- 持仓列表:所有头寸的完整明细
- 详细分析:资产配置、盈亏、风险标记
- 导出:JSON或CSV格式用于外部工具
Step 2: Execute Portfolio Tracking
步骤2:执行投资组合追踪
Run the tracker with appropriate options:
bash
undefined通过合适的选项运行追踪器:
bash
undefinedQuick portfolio summary
快速投资组合摘要
python {baseDir}/scripts/portfolio_tracker.py --portfolio holdings.json
python {baseDir}/scripts/portfolio_tracker.py --portfolio holdings.json
Full holdings breakdown
完整持仓明细
python {baseDir}/scripts/portfolio_tracker.py --portfolio holdings.json --holdings
python {baseDir}/scripts/portfolio_tracker.py --portfolio holdings.json --holdings
Detailed analysis with P&L and allocations
包含盈亏和配置的详细分析
python {baseDir}/scripts/portfolio_tracker.py --portfolio holdings.json --detailed
python {baseDir}/scripts/portfolio_tracker.py --portfolio holdings.json --detailed
Export to JSON
导出为JSON格式
python {baseDir}/scripts/portfolio_tracker.py --portfolio holdings.json --format json --output portfolio_export.json
python {baseDir}/scripts/portfolio_tracker.py --portfolio holdings.json --format json --output portfolio_export.json
Export to CSV
导出为CSV格式
python {baseDir}/scripts/portfolio_tracker.py --portfolio holdings.json --format csv --output portfolio.csv
undefinedpython {baseDir}/scripts/portfolio_tracker.py --portfolio holdings.json --format csv --output portfolio.csv
undefinedStep 3: Present Results
步骤3:展示结果
Format and explain the portfolio data:
- Show total portfolio value prominently
- Highlight 24h and 7d changes
- Explain allocation percentages
- Flag any concentration risks
- For detailed mode, explain P&L calculations
格式化并解读投资组合数据:
- 突出显示投资组合总价值
- 展示24小时和7天变化
- 解读配置占比
- 标记集中度风险
- 若为详细模式,解读盈亏计算逻辑
Command-Line Options
命令行选项
| Option | Description | Default |
|---|---|---|
| Path to portfolio JSON file | Required |
| Show all holdings breakdown | false |
| Full analysis with P&L | false |
| Sort by: value, allocation, name, change | value |
| Output format (table, json, csv) | table |
| Output file path | stdout |
| Allocation warning threshold | 25% |
| Enable verbose output | false |
| 选项 | 描述 | 默认值 |
|---|---|---|
| 投资组合JSON文件路径 | 必填 |
| 显示所有持仓明细 | false |
| 包含盈亏的完整分析 | false |
| 排序依据:value(价值)、allocation(配置占比)、name(名称)、change(涨跌幅) | value |
| 输出格式(table表格、json、csv) | table |
| 输出文件路径 | stdout |
| 配置占比预警阈值 | 25% |
| 启用详细输出 | false |
Allocation Thresholds
配置占比阈值
By default, positions > 25% allocation are flagged:
| Allocation | Risk Level | Action |
|---|---|---|
| < 10% | Low | Normal position |
| 10-25% | Medium | Monitor closely |
| 25-50% | High | Consider rebalancing |
| > 50% | Very High | Significant concentration risk |
默认情况下,配置占比>25%的头寸会被标记:
| 配置占比 | 风险等级 | 操作建议 |
|---|---|---|
| < 10% | 低 | 正常头寸 |
| 10-25% | 中 | 密切监控 |
| 25-50% | 高 | 考虑再平衡 |
| > 50% | 极高 | 显著集中度风险 |
Output
输出示例
Table Format (Default)
表格格式(默认)
==============================================================================
CRYPTO PORTFOLIO TRACKER Updated: 2026-01-14 15:30
==============================================================================
PORTFOLIO SUMMARY: My Portfolio
------------------------------------------------------------------------------
Total Value: $125,450.00 USD
24h Change: +$2,540.50 (+2.07%)
7d Change: +$8,125.00 (+6.92%)
Holdings: 8 assets
TOP HOLDINGS
------------------------------------------------------------------------------
Coin Quantity Price Value Alloc 24h
BTC 0.500 $95,000.00 $47,500.00 37.9% +2.5%
ETH 10.000 $3,200.00 $32,000.00 25.5% +1.8%
SOL 100.000 $180.00 $18,000.00 14.4% +4.2%
⚠ CONCENTRATION WARNING: BTC (37.9%) exceeds 25% threshold
============================================================================================================================================================
CRYPTO PORTFOLIO TRACKER Updated: 2026-01-14 15:30
==============================================================================
PORTFOLIO SUMMARY: My Portfolio
------------------------------------------------------------------------------
Total Value: $125,450.00 USD
24h Change: +$2,540.50 (+2.07%)
7d Change: +$8,125.00 (+6.92%)
Holdings: 8 assets
TOP HOLDINGS
------------------------------------------------------------------------------
Coin Quantity Price Value Alloc 24h
BTC 0.500 $95,000.00 $47,500.00 37.9% +2.5%
ETH 10.000 $3,200.00 $32,000.00 25.5% +1.8%
SOL 100.000 $180.00 $18,000.00 14.4% +4.2%
⚠ CONCENTRATION WARNING: BTC (37.9%) exceeds 25% threshold
==============================================================================JSON Format
JSON格式
json
{
"portfolio_name": "My Portfolio",
"total_value_usd": 125450.00,
"change_24h": {"amount": 2540.50, "percent": 2.07},
"holdings": [
{
"coin": "BTC",
"quantity": 0.5,
"price_usd": 95000,
"value_usd": 47500,
"allocation_pct": 37.9,
"change_24h_pct": 2.5
}
],
"meta": {
"timestamp": "2026-01-14T15:30:00Z",
"holdings_count": 8
}
}json
{
"portfolio_name": "My Portfolio",
"total_value_usd": 125450.00,
"change_24h": {"amount": 2540.50, "percent": 2.07},
"holdings": [
{
"coin": "BTC",
"quantity": 0.5,
"price_usd": 95000,
"value_usd": 47500,
"allocation_pct": 37.9,
"change_24h_pct": 2.5
}
],
"meta": {
"timestamp": "2026-01-14T15:30:00Z",
"holdings_count": 8
}
}Error Handling
错误处理
See for comprehensive error handling.
{baseDir}/references/errors.md| Error | Cause | Solution |
|---|---|---|
| Portfolio file not found | Invalid path | Check file path exists |
| Invalid JSON | Malformed file | Validate JSON syntax |
| Coin not found | Unknown symbol | Check symbol spelling, use standard symbols |
| API rate limited | Too many requests | Wait and retry, use caching |
完整的错误处理请参考 。
{baseDir}/references/errors.md| 错误 | 原因 | 解决方案 |
|---|---|---|
| 投资组合文件未找到 | 路径无效 | 检查文件路径是否存在 |
| JSON格式无效 | 文件格式错误 | 验证JSON语法 |
| 代币未找到 | 符号未知 | 检查符号拼写,使用标准符号 |
| API请求受限 | 请求次数过多 | 等待后重试,使用缓存 |
Examples
示例
See for detailed examples.
{baseDir}/references/examples.md详细示例请参考 。
{baseDir}/references/examples.mdQuick Examples
快速示例
bash
undefinedbash
undefinedBasic portfolio check
基础投资组合检查
python {baseDir}/scripts/portfolio_tracker.py --portfolio ~/crypto/holdings.json
python {baseDir}/scripts/portfolio_tracker.py --portfolio ~/crypto/holdings.json
Show all holdings sorted by allocation
按配置占比排序显示所有持仓
python {baseDir}/scripts/portfolio_tracker.py --portfolio holdings.json --holdings --sort allocation
python {baseDir}/scripts/portfolio_tracker.py --portfolio holdings.json --holdings --sort allocation
Detailed analysis with 15% threshold
阈值设为15%的详细分析
python {baseDir}/scripts/portfolio_tracker.py --portfolio holdings.json --detailed --threshold 15
python {baseDir}/scripts/portfolio_tracker.py --portfolio holdings.json --detailed --threshold 15
Export for tax software
导出至税务软件
python {baseDir}/scripts/portfolio_tracker.py --portfolio holdings.json --format csv --output tax_export.csv
python {baseDir}/scripts/portfolio_tracker.py --portfolio holdings.json --format csv --output tax_export.csv
JSON export for trading bot
导出JSON格式供交易机器人使用
python {baseDir}/scripts/portfolio_tracker.py --portfolio holdings.json --format json --output portfolio_data.json
undefinedpython {baseDir}/scripts/portfolio_tracker.py --portfolio holdings.json --format json --output portfolio_data.json
undefinedResources
资源
- CoinGecko API: https://www.coingecko.com/en/api - Free crypto market data
- Portfolio Schema: See PRD.md for complete portfolio file format
- Configuration: See for options
{baseDir}/config/settings.yaml - See for integration examples
{baseDir}/references/examples.md
- CoinGecko API:https://www.coingecko.com/en/api - 免费加密货币市场数据
- 投资组合 Schema:完整的投资组合文件格式请参考PRD.md
- 配置:选项请查看
{baseDir}/config/settings.yaml - 集成示例请参考
{baseDir}/references/examples.md