A comprehensive cryptocurrency trade tracker using the Coinbase Advanced Trade API. Track your trading performance, compare against BTC baseline, analyze historical profits, and visualize your portfolio growth over time.
- π Real-time Profit Tracking: Calculate realized and unrealized profits for all your trades
- π Historical Analysis: Generate daily historical profit data with actual market prices
- π― BTC Baseline Comparison: Compare your trading performance against a BTC-only investment strategy
- π Ticker Performance Analysis: Evaluate each coin's trading ROI vs simple HODL strategy
- π Automated Visualizations: Generate combined bar and line charts showing profit trends
- π€ Automated Daily Updates: Set up automatic data collection and chart generation at midnight
- πΎ Persistent Data Storage: All trade history, profit data, and charts are saved locally
CoinbaseTradeTracker/
βββ get_filled_history.py # Fetch trade history from Coinbase API
βββ calculate_profit_history.py # Calculate current profit with all comparisons
βββ calculate_profit_by_date.py # Calculate historical profit using historical prices
βββ generate_daily_history.py # Generate profit data for date ranges
βββ visualize_profit_history.py # Create charts from historical data
βββ daily_update.py # Automated daily update script
βββ setup_auto_update.sh # Setup automatic daily updates (macOS launchd)
βββ utils.py # Utility functions
βββ trade_history/ # Trade data from Coinbase API
βββ profit_history/ # Historical profit data (profit_begin_YYYYMMDD.json)
βββ comparison/ # Historical comparison data
βββ charts/ # Generated visualization charts
βββ logs/ # Log files from automated updates
git clone https://github.com/echo17666/CoinbaseTradeTracker.git
cd CoinbaseTradeTrackerconda create -n trade python=3.12 -y
conda activate tradepip install -r requirements.txtCreate a .env file in the root directory with your Coinbase API credentials:
COINBASE_API_KEY=your_api_key_here
COINBASE_API_SECRET_KEY=your_api_secret_key_hereTo get your API credentials:
- Go to Coinbase Advanced Trade
- Create a new API key with "View" permissions for trade data
- Copy the API Key and API Secret to your
.envfile
First delete existing data (if any) in the trade_history/, profit_history/, comparison/, and charts/ directories to start fresh.
Then run:
# Fetch all trade history
python get_filled_history.py
# Calculate current profit
python calculate_profit_history.py
# Generate historical data (e.g., last 30 days)
python generate_daily_history.py
# Create visualization charts
python visualize_profit_history.pyThere are two ways to automate daily updates:
Your computer runs the updates. Requirements: Computer must be powered on.
# Run the setup script
./setup_auto_update.shThe script will:
- Create a launchd plist file
- Schedule daily updates at 00:00 (midnight)
- Save logs to
./logs/directory
Useful commands:
# Check if auto-update is running
launchctl list | grep coinbase.tradetracker
# View logs
tail -f logs/daily_update_*.log
# Stop auto-update
launchctl unload ~/Library/LaunchAgents/com.coinbase.tradetracker.plist
# Start auto-update
launchctl load ~/Library/LaunchAgents/com.coinbase.tradetracker.plist
# Run update manually
python daily_update.py# Edit crontab
crontab -e
# Add this line (replace paths with your actual paths):
0 0 * * * cd /path/to/CoinbaseTradeTracker && /path/to/conda/envs/trade/bin/python daily_update.py >> logs/cron.log 2>&1- Open Task Scheduler
- Create a new task
- Set trigger to daily at midnight
- Set action to run:
python.exe C:\path\to\CoinbaseTradeTracker\daily_update.py - Set start in:
C:\path\to\CoinbaseTradeTracker
Run updates in the cloud - works even when your computer is off!
Pros:
- β Runs automatically without your computer
- β Free for public repositories
- β Data and charts automatically committed to repo
Cons:
β οΈ Your trade data will be stored in the GitHub repositoryβ οΈ API keys stored as GitHub Secrets (secure, but in cloud)β οΈ Recommendation: Use a private repository for sensitive financial data
Setup: See the detailed guide: GITHUB_ACTIONS_SETUP.md
Quick Overview:
- Add your Coinbase API credentials as GitHub Secrets
- Enable GitHub Actions workflow permissions
- Push the
.github/workflows/daily_update.ymlfile - Workflow runs automatically at midnight UTC daily
Fetch latest trades:
python get_filled_history.pyCalculate current profit:
python calculate_profit_history.pyGenerate historical data for a date range:
# Edit generate_daily_history.py and modify:
from datetime import date
start = date(2024, 11, 1) # Start date
end = date(2024, 11, 30) # End date
generate_daily_history(start, end)Then run:
python generate_daily_history.pyCreate visualization charts:
python visualize_profit_history.pyTrade History (trade_history/)
filled_alltime.json: All trades from Coinbase APIfilled_YYYYMMDD_YYYYMMDD.json: Trades within specific date range
Profit History (profit_history/)
profit_alltime.json: Current profit using current market pricesprofit_begin_YYYYMMDD.json: Cumulative profit from start to specific date (using historical prices)
Comparison Data (comparison/)
comparison_alltime.json: Current performance comparisonscomparison_begin_YYYYMMDD.json: Historical comparison data
Charts (charts/)
total_daily_profit.png: Overall portfolio profit (bar + line chart)daily_profit_all_coins.png: Per-coin profit breakdown (bar + line chart)vs_btc_all_coins.png: Performance vs BTC baselineroi_comparison_all_coins.png: Trading ROI vs HODL ROI
When running calculate_profit_history.py, you'll see:
1. Profit Summary
Coin Realized Unrealized Total
------------------------------------------------------------
ETH $ -0.24 $ -111.80 $ -112.04
USDC $ 0.00 $ 0.00 $ 0.00
FIL $ -4.08 $ -0.00 $ -4.08
DASH $ -25.27 $ 0.00 $ -25.27
BTC $ -8.54 $ -9.84 $ -18.38
SOL $ -36.17 $ -57.46 $ -93.63
ZEC $ 69.71 $ 108.10 $ 177.81
------------------------------------------------------------
TOTAL $ -4.58 $ -71.00 $ -75.58
2. BTC Baseline Comparison
======================================================================
BTC BASELINE COMPARISON (If All Investments Were in BTC)
======================================================================
Total Net Investment: $1,378.11
BTC Price (at first trade): $108,092.02
BTC Price (Current): $92,476.90
If All Invested in BTC:
BTC Amount: 0.01274939 BTC
Current Value: $1,179.02
Profit: $-199.08
ROI: -14.45%
Actual Trading Strategy:
Total Profit: $-75.11
ROI: -5.45%
π Strategy Outperforms BTC
Difference: $123.97 (+62.27%)
======================================================================
3. Ticker Performance Analysis
==================================================================================================================================
TICKER PRICE vs TRADING PERFORMANCE
==================================================================================================================================
Coin Start Time Start $ Current $ Price Change Net Investment My ROI Difference Status
----------------------------------------------------------------------------------------------------------------------------------
ETH 2025-10-22T00:34:38 $3841.00 $3036.32 π-20.95% $704.28 β-15.91% π’ +5.04% Holding
FIL 2025-11-07T16:15:06 $2.62 $1.87 π-28.72% $454.79 β -0.90% π’+27.83% Holding
BTC 2025-10-30T14:24:34 $107861 $92029 π-14.68% $211.82 β -8.68% π’ +6.00% Holding
SOL 2025-10-26T18:26:33 $199.19 $137.11 π-31.17% $288.20 β-32.49% π΄ -1.32% Holding
ZEC 2025-10-31T17:29:06 $373.88 $676.98 π 81.07% $336.96 β
52.77% π΄-28.30% Holding
----------------------------------------------------------------------------------------------------------------------------------
π Statistics:
Profitable Coins: 1/7 (14.3%)
Beat HODL: 4/7 (57.1%)
Average Price Change: -3.58%
Average Trading ROI: -2.36%
Total Profit: $-75.58
Overall ROI: -3.41%
==================================================================================================================================
4. Per-Ticker BTC Comparison
==========================================================================================
TICKER vs BTC COMPARISON (Each ticker uses its own first trade time)
==========================================================================================
Coin Start Time Actual If BTC Difference Better?
------------------------------------------------------------------------------------------
ETH 2025-10-22T00:34:38 $-112.04 $-367.59 $255.55 β
FIL 2025-11-07T16:15:06 $-4.08 $-39.41 $35.33 β
BTC 2025-10-30T14:24:34 $-18.38 $-81.70 $63.31 β
SOL 2025-10-26T18:26:33 $-93.63 $-249.43 $155.80 β
ZEC 2025-10-31T17:29:06 $177.81 $-451.97 $629.78 β
------------------------------------------------------------------------------------------
Coins Outperforming BTC: 7/7 (100.0%)
==========================================================================================
All charts combine stacked bar charts (showing realized/unrealized breakdown) with line charts (showing total profit trend):
Color Scheme:
- Bar Charts:
- Dark Green: Realized profit (positive)
- Dark Red: Realized loss (negative)
- Light Green: Unrealized profit (positive)
- Light Coral: Unrealized loss (negative)
- Line Chart:
- Blue line: Total cumulative profit
- Yellow labels: Dollar values at key points
Generated Charts:
total_daily_profit.png: Portfolio-wide cumulative profit over time
daily_profit_all_coins.png: Per-coin profit breakdown
vs_btc_all_coins.png: Your profit vs BTC alternative for each coin
roi_comparison_all_coins.png: Trading ROI vs price change (HODL ROI)
- Connects to Coinbase Advanced Trade API
- Fetches filled orders (buy/sell transactions)
- Incremental Mode: Merges new trades with existing data to avoid losing history
- Coinbase API limit: 2000 trades per request
- Daily updates use incremental mode to preserve all historical trades
- Detects duplicates using trade time, product ID, side, and price
- Saves to
trade_history/filled_alltime.json
- Realized Profit: Profit from completed trades (sold positions)
- Unrealized Profit: Current value - cost basis for holdings
- Uses current market prices from Coinbase API
- Compares performance against BTC baseline and HODL strategy
- For each historical date, fetches the actual market price at end of day
- Calculates profit as if you checked your portfolio on that date
- Generates cumulative profit data (all trades from start to that date)
- Uses historical 1-minute candle data for accurate pricing
- Reads all
profit_begin_*.jsonfiles - Creates combined bar + line charts:
- Bars: Show realized/unrealized composition
- Line: Show total profit trend
- Saves high-resolution charts (300 DPI)
- Runs all scripts in sequence
- Uses incremental mode to preserve all trade history
- Logs output to
logs/directory - Updates historical data with today's snapshot
- Regenerates all charts
- Realized: You've sold and locked in the profit/loss
- Unrealized: You still hold the asset, profit/loss can change
- Average price you paid for an asset
- Used to calculate unrealized profit:
(current_price - avg_buy_price) Γ quantity
ROI = (Total Profit / Net Investment) Γ 100%
- Hypothetical scenario: What if you invested everything in BTC?
- Compares your actual performance to this "passive" strategy
- Helps evaluate if your trading strategy adds value
- HODL ROI: Just buy and hold (price change %)
- Trading ROI: Your actual trading performance
- Positive difference = Your trading beats simple HODL
- Make sure
.envfile exists in project root - Check that
COINBASE_API_KEYandCOINBASE_API_SECRET_KEYare set
- Coinbase API rate limits may apply
- Wait a few seconds and retry
- Check your internet connection
- Make sure
matplotlibis installed:pip install matplotlib - Check that historical data exists in
profit_history/ - View logs in
logs/directory for error details
- macOS: Check launchd status with
launchctl list | grep coinbase - Linux: Check cron logs with
grep CRON /var/log/syslog - Make sure conda environment path in setup script is correct
Edit generate_daily_history.py:
from datetime import date
# Generate last 90 days
start_date = date(2024, 9, 1)
end_date = date(2024, 11, 30)
generate_daily_history(start_date, end_date)Edit setup_auto_update.sh to modify the hour/minute:
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>6</integer> <!-- 6 AM instead of midnight -->
<key>Minute</key>
<integer>30</integer> <!-- 30 minutes past the hour -->
</dict>Edit visualize_profit_history.py to change:
- Colors: Modify
realized_colorsandunrealized_colors - Figure size: Change
figsize=(14, 6) - DPI: Modify
dpi=300inplt.savefig()
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
This tool is for personal portfolio tracking only. It is not financial advice. Always verify important financial data independently. Past performance does not guarantee future results.
Created by echo17666
If you find this project helpful, please give it a β on GitHub!