If you are learning Python and want to build a real‑world, practical project, then this Cryptocurrency Price Tracker Python project is a perfect choice for you.
Instead of just practicing small examples, this project helps you understand how Python is actually used in real applications. You will learn how to work with live data from the internet and turn it into something meaningful and useful.
In this project, we will build a Python program that can:
- Fetch real‑time cryptocurrency prices
- Show 24‑hour price change
- Retrieve historical price data
- Display a clear and easy‑to‑understand price graph
What Is a Cryptocurrency Price Tracker Python Project?
Our program will:
- Ask the user to enter a cryptocurrency name (example: bitcoin)
- Show its current price in INR
- Display 24‑hour price change
- Ask for the number of days
- Plot a historical price graph
All data is fetched using the CoinGecko API, which is free and reliable.
Tools and Libraries Used in Cryptocurrency Price Tracker Python
Required Libraries
pip install requests matplotlib
| Library | Purpose |
|---|---|
| requests | Fetch data from CoinGecko API |
| matplotlib | Plot price graphs |
| datetime | Convert timestamps to dates |
Understanding CoinGecko API for Cryptocurrency Price Tracking in Python
An API is like a messenger that brings data from the internet.
CoinGecko provides:
- Real‑time crypto prices
- Historical price data
- No API key required
This makes it ideal for beginners.
Complete Code for Cryptocurrency Price Tracker Python Project
import requests
import matplotlib.pyplot as plt
import datetime
COINGECKO_API_URL = "https://api.coingecko.com/api/v3"
headers = {"accept": "application/json"}
def get_crypto_price(crypto_symbol):
response = requests.get(
f"{COINGECKO_API_URL}/simple/price",
params={
'ids': crypto_symbol,
'vs_currencies': 'inr',
'include_24hr_change': 'true'
},
headers=headers
)
if response.status_code == 200:
data = response.json()
if crypto_symbol in data:
price = data[crypto_symbol]['inr']
change = data[crypto_symbol]['inr_24h_change']
return price, change
else:
raise ValueError("Cryptocurrency not found")
else:
raise Exception("API request failed")
def get_historical_data(crypto_symbol, days):
response = requests.get(
f"{COINGECKO_API_URL}/coins/{crypto_symbol}/market_chart",
params={'vs_currency': 'inr', 'days': days}
)
if response.status_code == 200:
return response.json()['prices']
else:
raise Exception("Failed to fetch historical data")
def plot_historical_data(historical_data, crypto_symbol):
dates = [
datetime.datetime.fromtimestamp(item[0] / 1000)
for item in historical_data
]
prices = [item[1] for item in historical_data]
plt.figure(figsize=(10, 6))
plt.plot(dates, prices, color='blue')
plt.title(f"{crypto_symbol.capitalize()} Price History")
plt.xlabel("Date")
plt.ylabel("Price (INR)")
plt.xticks(rotation=45)
plt.grid(True)
plt.tight_layout()
plt.show()
def main():
crypto = input("Enter cryptocurrency name (eg. bitcoin): ").lower()
try:
price, change = get_crypto_price(crypto)
print(f"Current Price: ₹{price}")
print(f"24-hour Change: {change:.2f}%")
except Exception as e:
print("Error:", e)
return
while True:
try:
days = int(input("Enter number of days: "))
if days <= 0:
raise ValueError
break
except ValueError:
print("Please enter a valid number.")
historical_data = get_historical_data(crypto, days)
plot_historical_data(historical_data, crypto)
main()
Step-by-Step Code Explanation for Cryptocurrency Price Tracker Python
In this section, we will understand the codeslowly and clearly.
I will explainwhy each important line is writtenandwhat exactly it does.
Don’t rush. Read it like a story.
1. Importing Python Libraries for Cryptocurrency Price Tracker
import requests
What this line does:
This line imports therequestslibrary.
Why we need it:
Our program needs to talk to the CoinGecko website and ask for crypto prices.
requestshelps Pythonsend requests to the internetandreceive data back.
Without this library, Python cannot fetch online data.
import matplotlib.pyplot as plt
What this line does:
This imports the graph‑drawing tool from thematplotliblibrary.
Why we need it:
We want todraw a price graphfor the cryptocurrency history.
pltis just a short name that makes the code easier to write and read.
import datetime
What this line does:
This imports thedatetimemodule.
Why we need it:
CoinGecko sends time intimestamp format, which looks like a big number.
datetimeconverts that number intohuman‑readable dateslike:
2024‑05‑10
2. API URL and Headers
COINGECKO_API_URL = "https://api.coingecko.com/api/v3"
What this line does:
Stores the base URL of the CoinGecko API in a variable.
Why do we do this:
Instead of writing the full URL again and again, we store it once.
This makes the codecleanandeasy to update.
headers = {"accept": "application/json"}
What this line does:
Tells CoinGecko that we want the response inJSON format.
Why this is important:
JSON is easy for Python to understand and convert into dictionaries.
3. Getting Real‑Time Cryptocurrency Price
def get_crypto_price(crypto_symbol):
What this line does:
Creates a function namedget_crypto_price.
What is a function?
A function is a block of code that performs a task and can be reused.
Here:
This function will fetch thecurrent priceand24‑hour changeof a crypto.
response = requests.get(
What this line does:
Sends a GET request to the internet.
In simple words:
Python is saying:
“Hey CoinGecko, please send me the crypto price data.”
'ids': crypto_symbol
What this line does:
Tells the APIwhich cryptocurrencywe want.
Example:
- User entersbitcoin
- API fetches data for Bitcoin
'vs_currencies': 'inr'
What this line does:
Tells the API that we want the price inIndian Rupees (INR).
You can change it to:
- ‘usd’for US Dollars
- ‘eur’for Euro
'include_24hr_change': 'true'
What this line does:
Asks the API to include24‑hour price change percentage.
This helps users know if the price went up or down.
if response.status_code == 200:
What this line does:
Checks if the API request was successful.
Why 200?
200means:
Everything worked fine
Any other number means an error
data = response.json()
What this line does:
Converts the API response into a Python dictionary.
Now we can access data like:
data['bitcoin']['inr']
price = data[crypto_symbol]['inr']
What this line does:
Extracts thecurrent pricefrom the API data.
change = data[crypto_symbol]['inr_24h_change']
What this line does:
Extracts the24‑hour price change percentage.
return price, change
What this line does:
Sends the price and change back to the main program.
Python allows returningmultiple valuesat once.
4. Fetching Historical Crypto Price Data Using Python
def get_historical_data(crypto_symbol, days):
What this line does:
Creates a function to fetchpast price data.
- crypto_symbol→ crypto name
- days→ how many days of data
'vs_currency': 'inr'
What this line does:
Tells the API to return prices in INR.
'days': days
What this line does:
Defines the time range for historical data.
Example:
- 7 – last 7 days
- 30 – last 30 days
return response.json()['prices']
What this line does:
Returns only theprice listfrom the API response.
Each price entry contains:
[timestamp, price]
5. Plotting Cryptocurrency Price Graph Using Python
datetime.datetime.fromtimestamp(item[0] / 1000)
What this line does:
Converts a timestamp into a readable date.
Why divide by 1000?
CoinGecko gives time inmilliseconds, but Python expectsseconds.
prices = [item[1] for item in historical_data]
What this line does:
Extracts only the price values from the data.
plt.plot(dates, prices)
What this line does:
Draws the price line on the graph.
- X‑axis – dates
- Y‑axis – prices
plt.title(...)
What this line does:
Adds a title to the graph.
plt.show()
What this line does:
Displays the graph on the screen.
Without this line, the graph will not appear.
6. Main Program Flow
crypto = input().lower()
What this line does:
Takes user input and converts it to lowercase.
Why?
SoBitcoin,bitcoin, andBITCOINall work.
while True:
What this line does:
Creates a loop that keeps running until the correct input is given.
days = int(input())
What this line does:
Converts user input into a number.
If the user enters text, Python throws an error, which we handle.
main()
What this line does:
Starts the entire program.
Without this line, nothing will run.
To improve your data – handling skills further, check out our Python web scraping tutorial, where we explain how to extract data from websites step by step.
If you are new to Python, the Python official documentation is a great place to understand core concepts.
Conclusion
You’ve just built a real‑world Cryptocurrency Price Tracker Python project – and that’s a big step in your Python journey.
From fetching real‑time cryptocurrency prices using an API, to handling user input, working with real data, and finally visualizing that data using graphs, you’ve learned skills that real developers use every day. These are not just concepts for practice – they are practical tools that help you understand how Python works in real applications.
This project also introduced you to important ideas like APIs, error handling, and data visualization. Once you understand these building blocks, creating bigger and more advanced Python projects becomes much easier and more enjoyable.
At ConsoleFlare, we believe learning is best when it’s hands‑on and practical. That’s why we focus on real projects like this – so you don’t just write code, but actually understand why each line exists and how everything connects together.
This is only the beginning. With consistent practice and curiosity, you’ll soon be able to build more advanced applications, work with larger datasets, and confidently move toward professional‑level Python development.
Keep learning. Keep building. And remember – every confident developer started exactly where you are today.
For more beginner‑friendly Python tutorials, projects, and learning resources, follow us on Facebook, Instagram, and LinkedIn.


