{"id":239,"date":"2025-11-20T14:41:32","date_gmt":"2025-11-20T14:41:32","guid":{"rendered":"https:\/\/codetypingpro.com\/?p=239"},"modified":"2025-11-20T14:41:32","modified_gmt":"2025-11-20T14:41:32","slug":"33-real-world-python-projects-crypto-portfolio-tracker","status":"publish","type":"post","link":"https:\/\/codetypingpro.com\/?p=239","title":{"rendered":"33 &#8211; Real-World Python Projects &#8211; Crypto Portfolio Tracker"},"content":{"rendered":"\n<h6 class=\"wp-block-heading\"><\/h6>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Purpose<\/strong><\/h3>\n\n\n\n<p>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.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83e\udde0 <strong>What the Project Will Do<\/strong><\/h1>\n\n\n\n<p>\u2714 Track your crypto holdings (BTC, ETH, Solana, etc.)<br>\u2714 Fetch <strong>live market prices<\/strong> using an API<br>\u2714 Calculate:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Total portfolio value<\/li>\n\n\n\n<li>Individual crypto value<\/li>\n\n\n\n<li>Profit\/loss per coin<\/li>\n\n\n\n<li>Total profit\/loss<br>\u2714 Visualize portfolio using a pie chart<br>\u2714 Auto-refresh every X seconds<br>\u2714 Export daily report to CSV<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83e\uddf0 <strong>Tech Stack<\/strong><\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>requests<\/code> (API calls)<\/li>\n\n\n\n<li><code>pandas<\/code><\/li>\n\n\n\n<li><code>matplotlib<\/code><\/li>\n\n\n\n<li><code>json<\/code><\/li>\n\n\n\n<li>(Optional) <code>schedule<\/code> for automation<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udcc1 Folder Structure<\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>Crypto_Portfolio_Tracker\/\n\u2502\u2500\u2500 portfolio.json\n\u2502\u2500\u2500 tracker.py\n\u2502\u2500\u2500 output\/\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udcc4 <strong>portfolio.json (Your holdings)<\/strong><\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n    \"BTC\": 0.05,\n    \"ETH\": 1.2,\n    \"SOL\": 15,\n    \"XRP\": 200,\n    \"DOGE\": 3000\n}\n<\/code><\/pre>\n\n\n\n<p>You can add any coins.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udd17 <strong>Live Price API<\/strong><\/h1>\n\n\n\n<p>We use <strong>CoinGecko<\/strong> free API (no key required):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>https:&#47;&#47;api.coingecko.com\/api\/v3\/simple\/price\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83e\udde0 <strong>Full Python Code: <code>tracker.py<\/code><\/strong><\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>import json\nimport requests\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom datetime import datetime\n\n# Load portfolio\nwith open(\"portfolio.json\") as f:\n    portfolio = json.load(f)\n\ncoins = \",\".join(portfolio.keys()).lower()\n\n# Fetch live prices\nurl = f\"https:\/\/api.coingecko.com\/api\/v3\/simple\/price?ids={coins}&amp;vs_currencies=usd\"\nprices = requests.get(url).json()\n\ndata = &#91;]\ntotal_value = 0\n\nfor coin, qty in portfolio.items():\n    coin_id = coin.lower()\n    price = prices&#91;coin_id]&#91;\"usd\"]\n    value = price * qty\n    total_value += value\n\n    data.append({\n        \"Coin\": coin,\n        \"Quantity\": qty,\n        \"Live Price (USD)\": price,\n        \"Total Value (USD)\": value\n    })\n\ndf = pd.DataFrame(data)\ndf.loc&#91;\"TOTAL\"] = &#91;\"-\", \"-\", \"-\", total_value]\n\nprint(df)\n\n# Save CSV\ntimestamp = datetime.now().strftime(\"%Y-%m-%d_%H-%M\")\ncsv_path = f\"output\/Portfolio_{timestamp}.csv\"\ndf.to_csv(csv_path, index=False)\n\n# Chart\nplt.figure(figsize=(6, 6))\nplt.pie(&#91;row&#91;\"Total Value (USD)\"] for row in data],\n        labels=&#91;row&#91;\"Coin\"] for row in data],\n        autopct=\"%1.1f%%\")\nplt.title(\"Crypto Portfolio Distribution\")\nplt.show()\n\nprint(\"Saved:\", csv_path)\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udfe6 <strong>Example Output<\/strong><\/h1>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Coin<\/th><th>Quantity<\/th><th>Live Price<\/th><th>Total Value<\/th><\/tr><\/thead><tbody><tr><td>BTC<\/td><td>0.05<\/td><td>96,200<\/td><td>4,810<\/td><\/tr><tr><td>ETH<\/td><td>1.2<\/td><td>2,480<\/td><td>2,976<\/td><\/tr><tr><td>SOL<\/td><td>15<\/td><td>210<\/td><td>3,150<\/td><\/tr><tr><td>XRP<\/td><td>200<\/td><td>0.64<\/td><td>128<\/td><\/tr><tr><td>DOGE<\/td><td>3000<\/td><td>0.12<\/td><td>360<\/td><\/tr><tr><td><strong>TOTAL<\/strong><\/td><td>\u2014<\/td><td>\u2014<\/td><td><strong>11,424 USD<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udcca Portfolio Pie Chart<\/h1>\n\n\n\n<p>Shows the percentage of each crypto\u2019s share in your portfolio.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\ude80 <strong>Advanced Features You Can Add<\/strong><\/h1>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Telegram\/WhatsApp Alerts<\/strong><\/h3>\n\n\n\n<p>Notify when:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>BTC &lt; $90,000<\/li>\n\n\n\n<li>ETH > $3,000<\/li>\n\n\n\n<li>SOL drops 10%<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Auto-Refresh Mode<\/strong><\/h3>\n\n\n\n<p>Refresh every 5 seconds:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import time\nwhile True:\n    run_tracker()\n    time.sleep(5)\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Historical Tracking<\/strong><\/h3>\n\n\n\n<p>Store values daily \u2192 generate profit\/loss graphs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Dashboard With Streamlit<\/strong><\/h3>\n\n\n\n<p>Live charts<br>Search coins<br>Dark mode UI<br>Realtime updates<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Multiply on Rebalancing<\/strong><\/h3>\n\n\n\n<p>Tell you which coins to buy\/sell to maintain your ratio.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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. \ud83e\udde0 What the Project Will Do \u2714 Track your crypto holdings (BTC, ETH, Solana, etc.)\u2714 Fetch live market prices using an API\u2714 Calculate: \ud83e\uddf0 Tech Stack \ud83d\udcc1 Folder Structure \ud83d\udcc4 portfolio.json [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-239","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/codetypingpro.com\/index.php?rest_route=\/wp\/v2\/posts\/239","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codetypingpro.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codetypingpro.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codetypingpro.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codetypingpro.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=239"}],"version-history":[{"count":1,"href":"https:\/\/codetypingpro.com\/index.php?rest_route=\/wp\/v2\/posts\/239\/revisions"}],"predecessor-version":[{"id":240,"href":"https:\/\/codetypingpro.com\/index.php?rest_route=\/wp\/v2\/posts\/239\/revisions\/240"}],"wp:attachment":[{"href":"https:\/\/codetypingpro.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=239"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codetypingpro.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=239"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codetypingpro.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=239"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}