
Build a Crypto Portfolio Tracker in Python: Live Prices, P&L & Allocation in 150 Lines
Tags: python, crypto, bitcoin, programming I got tired of switching between 4 tabs to check my crypto portfolio. So I built a simple Python tracker that pulls live prices, calculates P&L, and shows portfolio allocation — no API key needed. Here's what it does: Fetches live prices from CoinGecko (free, no signup) Calculates profit/loss per coin and overall Shows portfolio allocation as percentages Saves history to a JSON file The Full Script import json import urllib.request import datetime import os PORTFOLIO_FILE = " portfolio.json " HISTORY_FILE = " history.json " # Your holdings — edit this DEFAULT_PORTFOLIO = { " bitcoin " : { " amount " : 0.1 , " avg_buy_price " : 35000 }, " ethereum " : { " amount " : 1.5 , " avg_buy_price " : 2200 }, " solana " : { " amount " : 10 , " avg_buy_price " : 120 }, } def load_portfolio (): if os . path . exists ( PORTFOLIO_FILE ): with open ( PORTFOLIO_FILE ) as f : return json . load ( f ) return DEFAULT_PORTFOLIO def save_portfolio ( portfolio ): wi
Continue reading on Dev.to Python
Opens in a new tab




