Skip to content

Commit 9acd44c

Browse files
Initial commit - Crypto Portfolio Tracker
0 parents  commit 9acd44c

11 files changed

+136
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 ajay-techspace
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Crypto Portfolio Tracker
2+
3+
A simple Python project to track your cryptocurrency portfolio, calculate returns, and visualize your holdings.
4+
5+
## Features
6+
7+
- Calculates profit/loss for each coin
8+
- Fetches live prices (or use manual prices)
9+
- Visualizes portfolio distribution with charts
10+
11+
## Setup
12+
13+
1. Clone the repo:
14+
```
15+
git clone https://github.com/ajay-techspace/crypto_portfolio_tracker.git
16+
cd crypto-portfolio-tracker
17+
```
18+
19+
2. Install dependencies:
20+
```
21+
pip install -r requirements.txt
22+
```
23+
24+
3. Add your portfolio to `portfolio.csv` (see sample below).
25+
26+
## Usage
27+
28+
Run the main script:
29+
```
30+
python main.py
31+
```
32+
33+
## Sample `portfolio.csv`
34+
35+
| coin | quantity | buy_price |
36+
|----------|----------|-----------|
37+
| bitcoin | 0.5 | 20000 |
38+
| ethereum | 2 | 1500 |
39+
40+
## Requirements
41+
42+
- pandas
43+
- requests
44+
- matplotlib
45+
46+
## License
47+
48+
This project is licensed under the [MIT License](./LICENSE).
886 Bytes
Binary file not shown.
812 Bytes
Binary file not shown.

__pycache__/visualize.cpython-313.pyc

949 Bytes
Binary file not shown.

calculate_returns.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import pandas as pd
2+
from fetch_prices import fetch_price
3+
4+
def calculate_returns(df):
5+
if 'current_price' not in df.columns or df['current_price'].isnull().any():
6+
df['current_price'] = df['coin'].apply(fetch_price)
7+
df['cost'] = df['quantity'] * df['buy_price']
8+
df['value'] = df['quantity'] * df['current_price']
9+
df['profit_loss'] = df['value'] - df['cost']
10+
return df

fetch_prices.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import requests
2+
3+
def fetch_price(coin_id):
4+
url = f"https://api.coingecko.com/api/v3/simple/price?ids={coin_id}&vs_currencies=usd"
5+
try:
6+
response = requests.get(url)
7+
data = response.json()
8+
return data[coin_id]['usd']
9+
except Exception as e:
10+
print(f"Error fetching price for {coin_id}: {e}")
11+
return None

main.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import pandas as pd
2+
from calculate_returns import calculate_returns
3+
from visualize import plot_portfolio
4+
5+
def main():
6+
df = pd.read_csv("portfolio.csv")
7+
8+
# 🔧 Use manual prices (no API)
9+
manual_prices = {
10+
'bitcoin': 26000,
11+
'ethereum': 1800
12+
}
13+
df['current_price'] = df['coin'].map(manual_prices)
14+
15+
# ✅ Calculate results
16+
df = calculate_returns(df)
17+
print(df)
18+
19+
print("\n--- Portfolio Summary ---")
20+
print(df[['coin', 'quantity', 'buy_price', 'current_price', 'cost', 'value', 'profit_loss']])
21+
22+
plot_portfolio(df)
23+
24+
if __name__ == "__main__":
25+
main()

portfolio.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coin,quantity,buy_price
2+
bitcoin,0.5,25000
3+
ethereum,1.0,1800

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
requests
2+
pandas
3+
matplotlib

0 commit comments

Comments
 (0)