tracking-crypto-portfolio

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Tracking 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:
  1. Python 3.8+ is installed
  2. requests library is available:
    pip install requests
  3. Internet connectivity for CoinGecko API access
  4. A portfolio JSON file with your holdings
使用本工具前,请确保:
  1. 已安装 Python 3.8+
  2. 已安装 requests 库:
    pip install requests
  3. 具备网络连接以访问CoinGecko API
  4. 拥有包含您持仓信息的投资组合JSON文件

Portfolio File Format

投资组合文件格式

Create a portfolio file (e.g.,
holdings.json
):
json
{
  "name": "My Portfolio",
  "holdings": [
    {"coin": "BTC", "quantity": 0.5, "cost_basis": 25000},
    {"coin": "ETH", "quantity": 10, "cost_basis": 2000},
    {"coin": "SOL", "quantity": 100}
  ]
}
Fields:
  • coin
    : Symbol (BTC, ETH, etc.) - required
  • quantity
    : Amount held - required
  • cost_basis
    : Average purchase price per coin (optional, for P&L)
  • acquired
    : Date acquired (optional, for records)
创建投资组合文件(例如
holdings.json
):
json
{
  "name": "My Portfolio",
  "holdings": [
    {"coin": "BTC", "quantity": 0.5, "cost_basis": 25000},
    {"coin": "ETH", "quantity": 10, "cost_basis": 2000},
    {"coin": "SOL", "quantity": 100}
  ]
}
字段说明:
  • coin
    :代币符号(BTC、ETH等)- 必填
  • 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
undefined

Quick 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
undefined
python {baseDir}/scripts/portfolio_tracker.py --portfolio holdings.json --format csv --output portfolio.csv
undefined

Step 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

命令行选项

OptionDescriptionDefault
--portfolio
Path to portfolio JSON fileRequired
--holdings
Show all holdings breakdownfalse
--detailed
Full analysis with P&Lfalse
--sort
Sort by: value, allocation, name, changevalue
--format
Output format (table, json, csv)table
--output
Output file pathstdout
--threshold
Allocation warning threshold25%
--verbose
Enable verbose outputfalse
选项描述默认值
--portfolio
投资组合JSON文件路径必填
--holdings
显示所有持仓明细false
--detailed
包含盈亏的完整分析false
--sort
排序依据:value(价值)、allocation(配置占比)、name(名称)、change(涨跌幅)value
--format
输出格式(table表格、json、csv)table
--output
输出文件路径stdout
--threshold
配置占比预警阈值25%
--verbose
启用详细输出false

Allocation Thresholds

配置占比阈值

By default, positions > 25% allocation are flagged:
AllocationRisk LevelAction
< 10%LowNormal position
10-25%MediumMonitor closely
25-50%HighConsider rebalancing
> 50%Very HighSignificant 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
{baseDir}/references/errors.md
for comprehensive error handling.
ErrorCauseSolution
Portfolio file not foundInvalid pathCheck file path exists
Invalid JSONMalformed fileValidate JSON syntax
Coin not foundUnknown symbolCheck symbol spelling, use standard symbols
API rate limitedToo many requestsWait and retry, use caching
完整的错误处理请参考
{baseDir}/references/errors.md
错误原因解决方案
投资组合文件未找到路径无效检查文件路径是否存在
JSON格式无效文件格式错误验证JSON语法
代币未找到符号未知检查符号拼写,使用标准符号
API请求受限请求次数过多等待后重试,使用缓存

Examples

示例

See
{baseDir}/references/examples.md
for detailed examples.
详细示例请参考
{baseDir}/references/examples.md

Quick Examples

快速示例

bash
undefined
bash
undefined

Basic 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
undefined
python {baseDir}/scripts/portfolio_tracker.py --portfolio holdings.json --format json --output portfolio_data.json
undefined

Resources

资源

  • CoinGecko API: https://www.coingecko.com/en/api - Free crypto market data
  • Portfolio Schema: See PRD.md for complete portfolio file format
  • Configuration: See
    {baseDir}/config/settings.yaml
    for options
  • See
    {baseDir}/references/examples.md
    for integration examples
  • CoinGecko APIhttps://www.coingecko.com/en/api - 免费加密货币市场数据
  • 投资组合 Schema:完整的投资组合文件格式请参考PRD.md
  • 配置:选项请查看
    {baseDir}/config/settings.yaml
  • 集成示例请参考
    {baseDir}/references/examples.md