Purpose
A real-time Python system that tracks cryptocurrency investments, calculates profit/loss, fetches live prices, draws charts, and notifies the user when prices hit targets.
π§ What the Project Will Do
β Track your crypto holdings (BTC, ETH, Solana, etc.)
β Fetch live market prices using an API
β Calculate:
- Total portfolio value
- Individual crypto value
- Profit/loss per coin
- Total profit/loss
β Visualize portfolio using a pie chart
β Auto-refresh every X seconds
β Export daily report to CSV
π§° Tech Stack
requests(API calls)pandasmatplotlibjson- (Optional)
schedulefor automation
π Folder Structure
Crypto_Portfolio_Tracker/
βββ portfolio.json
βββ tracker.py
βββ output/
π portfolio.json (Your holdings)
{
"BTC": 0.05,
"ETH": 1.2,
"SOL": 15,
"XRP": 200,
"DOGE": 3000
}
You can add any coins.
π Live Price API
We use CoinGecko free API (no key required):
https://api.coingecko.com/api/v3/simple/price
π§ Full Python Code: tracker.py
import json
import requests
import pandas as pd
import matplotlib.pyplot as plt
from datetime import datetime
# Load portfolio
with open("portfolio.json") as f:
portfolio = json.load(f)
coins = ",".join(portfolio.keys()).lower()
# Fetch live prices
url = f"https://api.coingecko.com/api/v3/simple/price?ids={coins}&vs_currencies=usd"
prices = requests.get(url).json()
data = []
total_value = 0
for coin, qty in portfolio.items():
coin_id = coin.lower()
price = prices[coin_id]["usd"]
value = price * qty
total_value += value
data.append({
"Coin": coin,
"Quantity": qty,
"Live Price (USD)": price,
"Total Value (USD)": value
})
df = pd.DataFrame(data)
df.loc["TOTAL"] = ["-", "-", "-", total_value]
print(df)
# Save CSV
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M")
csv_path = f"output/Portfolio_{timestamp}.csv"
df.to_csv(csv_path, index=False)
# Chart
plt.figure(figsize=(6, 6))
plt.pie([row["Total Value (USD)"] for row in data],
labels=[row["Coin"] for row in data],
autopct="%1.1f%%")
plt.title("Crypto Portfolio Distribution")
plt.show()
print("Saved:", csv_path)
π¦ Example Output
| Coin | Quantity | Live Price | Total Value |
|---|---|---|---|
| BTC | 0.05 | 96,200 | 4,810 |
| ETH | 1.2 | 2,480 | 2,976 |
| SOL | 15 | 210 | 3,150 |
| XRP | 200 | 0.64 | 128 |
| DOGE | 3000 | 0.12 | 360 |
| TOTAL | β | β | 11,424 USD |
π Portfolio Pie Chart
Shows the percentage of each cryptoβs share in your portfolio.
π Advanced Features You Can Add
1. Telegram/WhatsApp Alerts
Notify when:
- BTC < $90,000
- ETH > $3,000
- SOL drops 10%
2. Auto-Refresh Mode
Refresh every 5 seconds:
import time
while True:
run_tracker()
time.sleep(5)
3. Historical Tracking
Store values daily β generate profit/loss graphs.
4. Dashboard With Streamlit
Live charts
Search coins
Dark mode UI
Realtime updates
5. Multiply on Rebalancing
Tell you which coins to buy/sell to maintain your ratio.

Leave a Reply