I watched a friend pay $30/month for CoinMarketCap Pro to track his crypto portfolio. I built the same thing in 30 minutes — for free, with no API key.
CoinGecko has the most generous free API in crypto. Here's how to use it.
Why CoinGecko API?
- No API key needed for basic endpoints (just make HTTP requests)
- 13,000+ cryptocurrencies tracked
- Exchange data from 800+ exchanges
- Historical data going back years
- NFT data included
- Rate limit: 10-30 requests/minute (free)
Step 1: Get Current Prices (No Key Needed!)
import requests
def get_crypto_prices(coins, currency="usd"):
"""Get current prices for multiple cryptocurrencies."""
url = "https://api.coingecko.com/api/v3/simple/price"
params = {
"ids": ",".join(coins),
"vs_currencies": currency,
"include_24hr_change": "true",
"include_market_cap": "true",
}
return requests.get(url, params=params).json()
# Get prices for top cryptos
prices = get_crypto_prices(["bitcoin", "ethereum", "solana", "cardano"])
for coin, data in prices.items():
price = data["usd"]
change = data["usd_24h_change"]
emoji = "📈" if change > 0 else "📉"
print(f"{emoji} {coin.title()}: ${price:,.2f} ({change:+.1f}%)")
Output:
📈 Bitcoin: $67,234.00 (+2.3%)
📉 Ethereum: $3,456.78 (-1.2%)
📈 Solana: $178.90 (+5.4%)
📉 Cardano: $0.45 (-0.8%)
Step 2: Portfolio Tracker
# Your portfolio
PORTFOLIO = {
"bitcoin": 0.5, # 0.5 BTC
"ethereum": 3.0, # 3 ETH
"solana": 25.0, # 25 SOL
"cardano": 5000.0, # 5000 ADA
}
def portfolio_value():
"""Calculate total portfolio value."""
coins = list(PORTFOLIO.keys())
prices = get_crypto_prices(coins)
total = 0
print(f"\n{Coin:<12} {Amount:>10} {Price:>12} {Value:>12} {24h:>8}")
print("-" * 58)
for coin, amount in PORTFOLIO.items():
price = prices[coin]["usd"]
value = price * amount
change = prices[coin]["usd_24h_change"]
total += value
print(f"{coin.title():<12} {amount:>10.2f} ${price:>10,.2f} ${value:>10,.2f} {change:>+7.1f}%")
print("-" * 58)
print(f"{TOTAL:<12} {:>10} {:>12} ${total:>10,.2f}")
return total
portfolio_value()
Step 3: Historical Data & Charts
import matplotlib.pyplot as plt
from datetime import datetime
def get_price_history(coin_id, days=30):
"""Get historical prices."""
url = f"https://api.coingecko.com/api/v3/coins/{coin_id}/market_chart"
params = {"vs_currency": "usd", "days": days}
data = requests.get(url, params=params).json()
prices = data["prices"] # [[timestamp, price], ...]
dates = [datetime.fromtimestamp(p[0]/1000) for p in prices]
values = [p[1] for p in prices]
return dates, values
# Compare BTC vs ETH (normalized)
fig, ax = plt.subplots(figsize=(12, 6))
for coin in ["bitcoin", "ethereum", "solana"]:
dates, values = get_price_history(coin, 90)
normalized = [(v / values[0] - 1) * 100 for v in values]
ax.plot(dates, normalized, label=coin.title())
ax.set_title("90-Day Crypto Performance (% Change)")
ax.set_ylabel("% Change from Start")
ax.legend()
ax.grid(True, alpha=0.3)
plt.tight_layout()
plt.savefig("crypto_comparison.png", dpi=150)
Step 4: Fear & Greed Index Alternative
def get_market_overview():
"""Build your own market sentiment indicator."""
url = "https://api.coingecko.com/api/v3/global"
data = requests.get(url).json()["data"]
btc_dominance = data["market_cap_percentage"]["btc"]
total_mcap = data["total_market_cap"]["usd"]
mcap_change = data["market_cap_change_percentage_24h_usd"]
# Simple sentiment based on 24h market change
if mcap_change > 5:
sentiment = "🟢 Extreme Greed"
elif mcap_change > 2:
sentiment = "🟢 Greed"
elif mcap_change > -2:
sentiment = "🟡 Neutral"
elif mcap_change > -5:
sentiment = "🔴 Fear"
else:
sentiment = "🔴 Extreme Fear"
print(f"Total Crypto Market Cap: ${total_mcap/1e12:.2f}T")
print(f"24h Change: {mcap_change:+.2f}%")
print(f"BTC Dominance: {btc_dominance:.1f}%")
print(f"Sentiment: {sentiment}")
get_market_overview()
Step 5: Trending Coins (What's Hot?)
def get_trending():
"""What's trending on CoinGecko right now?"""
url = "https://api.coingecko.com/api/v3/search/trending"
data = requests.get(url).json()
print("🔥 Trending Coins (last 24h):")
for item in data["coins"][:7]:
coin = item["item"]
print(f" #{coin['market_cap_rank']} {coin['name']} ({coin['symbol']}) "
f"— Score: {coin['score']}")
get_trending()
CoinGecko vs Paid Alternatives
| Feature | CoinGecko (Free) | CoinMarketCap Pro ($30/mo) | Messari ($30/mo) |
|---|---|---|---|
| API Key Required | ❌ No | ✅ Yes | ✅ Yes |
| Coins tracked | 13,000+ | 9,000+ | 5,000+ |
| Historical data | ✅ | ✅ | ✅ |
| NFT data | ✅ | ❌ | ❌ |
| Exchange data | 800+ | 600+ | 200+ |
| Rate limit | 10-30/min | 30/min | 20/min |
| Price | $0 | $30/mo | $30/mo |
Full Code on GitHub
The complete portfolio tracker with alerts, charts, and Telegram notifications is on my GitHub.
Want custom crypto tools? I build API integrations, trading bots, and data pipelines. Check my portfolio or connect on GitHub.
More in this series: SEC EDGAR API | FRED API | Alpha Vantage API
Top comments (0)