Broad crypto market data from CoinGecko covering 13,000+ tokens. Global market stats, historical price data going back years, exchange volumes, trending tokens, and category filters. Best for macro analysis and long-term historical data.
Query the CoinGecko API for comprehensive crypto market data — prices, historical charts, exchange volumes, trending tokens, global stats, and category breakdowns. The free tier requires no API key and supports 30 calls/min.
Use Birdeye or DexScreener instead for real-time Solana DEX data, new token launches, or sub-daily granularity on Solana tokens.
import httpx
# No API key needed for free tier
resp = httpx.get(
"https://api.coingecko.com/api/v3/simple/price",
params={"ids": "solana,bitcoin,ethereum", "vs_currencies": "usd",
"include_24hr_change": "true"},
)
data = resp.json()
for coin, info in data.items():
print(f"{coin}: ${info['usd']:.2f} ({info['usd_24h_change']:+.1f}%)")
import httpx
resp = httpx.get(
"https://api.coingecko.com/api/v3/coins/markets",
params={"vs_currency": "usd", "order": "market_cap_desc",
"per_page": 10, "page": 1, "sparkline": "false"},
)
for coin in resp.json():
print(f"{coin['symbol'].upper():>6} ${coin['current_price']:>10,.2f} "
f"MCap: ${coin['market_cap']/1e9:.1f}B "
f"24h: {coin['price_change_percentage_24h']:+.1f}%")
import httpx
import pandas as pd
resp = httpx.get(
"https://api.coingecko.com/api/v3/coins/solana/market_chart",
params={"vs_currency": "usd", "days": "90", "interval": "daily"},
)
data = resp.json()
df = pd.DataFrame(data["prices"], columns=["timestamp", "price"])
df["date"] = pd.to_datetime(df["timestamp"], unit="ms")
df = df.set_index("date").drop(columns=["timestamp"])
print(df.describe())
import httpx
resp = httpx.get(
"https://api.coingecko.com/api/v3/coins/solana/ohlc",
params={"vs_currency": "usd", "days": "30"},
)
# Returns [[timestamp, open, high, low, close], ...]
candles = resp.json()
for c in candles[-5:]:
print(f" O={c[1]:.2f} H={c[2]:.2f} L={c[3]:.2f} C={c[4]:.2f}")
import httpx
resp = httpx.get("https://api.coingecko.com/api/v3/global")
g = resp.json()["data"]
print(f"Total Market Cap: ${g['total_market_cap']['usd']/1e12:.2f}T")
print(f"24h Volume: ${g['total_volume']['usd']/1e9:.0f}B")
print(f"BTC Dominance: {g['market_cap_percentage']['btc']:.1f}%")
print(f"Active Coins: {g['active_cryptocurrencies']:,}")
import httpx
resp = httpx.get("https://api.coingecko.com/api/v3/search/trending")
for item in resp.json()["coins"]:
coin = item["item"]
print(f"#{coin['market_cap_rank'] or '?':>4} {coin['name']} ({coin['symbol']})")
The free tier requires no API key (30 calls/min). For higher limits, get a Pro key from https://www.coingecko.com/en/api/pricing and set:
export COINGECKO_API_KEY="CG-xxxxxxxxxxxxxxxxxxxx"
Pro requests use a different base URL and header:
import os, httpx
API_KEY = os.getenv("COINGECKO_API_KEY", "")
if API_KEY:
BASE_URL = "https://pro-api.coingecko.com/api/v3"
HEADERS = {"x-cg-pro-api-key": API_KEY}