DEV Community

Quill Datafix
Quill Datafix

Posted on

Where to Get Free Historical Crypto Price Data in Python (7 Sources, No Paid API)

I keep a small Python backtesting toolkit, and the question I hear most from people starting out is not "how do I backtest" — it's "where do I get the price data without paying $29–$199/month for a market data subscription?"

Fair question. If you're validating a strategy idea on BTC or ETH daily candles, a Polygon or Kaiko subscription is massive overkill. Free sources will get you years of daily data and months of intraday candles — more than enough to decide whether an idea is worth refining.

Here are the 7 sources I actually pull from, with the constraints that matter (depth × granularity × whether you need a key). No affiliate links; all public endpoints.

1. Binance public klines — the workhorse

No key. No signup. 1000 candles per request, intervals from 1s to 1M.

import pandas as pd, requests

def binance_klines(symbol="BTCUSDT", interval="1d", limit=1000):
    url = "https://api.binance.com/api/v3/klines"
    rows = requests.get(url, params={"symbol": symbol, "interval": interval, "limit": limit}).json()
    return pd.DataFrame(rows, columns=[
        "open_time","open","high","low","close","volume","close_time",
        "quote_vol","trades","taker_base","taker_quote","ignore"])

df = binance_klines()
df[["open","high","low","close","volume"]] = df[["open","high","low","close","volume"]].astype(float)
Enter fullscreen mode Exit fullscreen mode

Gotchas: rate limit is a weight budget (~1200 weight/min; a klines call costs 1–2). Paginate with startTime for multi-year pulls. US users may need api.binance.us instead — same shape.

2. Coinbase Exchange candles

GET https://api.exchange.coinbase.com/products/BTC-USD/candles?granularity=86400 — public, no key. Max 300 candles per call, so year-long pulls need ~2 requests/month boundaries. Granularity: 60 / 300 / 900 / 3600 / 21600 / 86400 only.

3. Kraken public OHLC

GET https://api.kraken.com/0/public/OHLC?pair=XBTUSD&interval=1440 — returns up to 720 candles in one shot, no key. Intervals in minutes (1, 5, 15, 30, 60, 240, 1440, ...). Note Kraken's pair naming (XBT not BTC).

4. CoinGecko free API

/api/v3/coins/bitcoin/market_chart?vs_currency=usd&days=365 gives daily prices/volumes as JSON arrays. Free tier (with a demo key) covers 365 days of history; hourly for the last ~90. Rate limit is the tight part: roughly 10–30 calls/min depending on plan. Good for cross-checking or altcoin coverage; bad for bulk pulls.

5. yfinance — crypto tickers just work

Yahoo treats crypto as BTC-USD, ETH-USD, SOL-USD, etc. One line per ticker, up to ~10 years of daily, ~730 days of hourly (interval="1h" is capped).

import yfinance as yf
df = yf.download("BTC-USD", period="max", interval="1d")
Enter fullscreen mode Exit fullscreen mode

Data quality is decent but not exchange-grade: occasional gaps and adjusted-close quirks. Fine for idea validation, not for tick-level research.

6. ccxt — one wrapper, 100+ exchanges

pip install ccxt gives you exchange.fetch_ohlcv("BTC/USDT", "1h") across Binance, Kraken, OKX, Bybit... Each exchange still enforces its own limits (ccxt handles pagination helpers but read the docs per exchange). Use it when you need the same strategy checked across venues, not for a single pair.

7. CryptoCompare free tier

min-api.cryptocompare.com/data/v2/histoday?fsym=BTC&tsym=USD&limit=2000 — the free key covers thousands of daily candles, plus histohour. Limit: 2000 bars per call, free-tier rate limits apply. Deep history is its main selling point.

Cheat sheet

Source Key needed Daily depth Intraday Best for
Binance klines no years 1s–1d bulk pulls, any interval
Coinbase candles no ~years (paginate) 1m–1d US-friendly fallback
Kraken OHLC no ~2y (paginate) 1m–1d quick 720-candle grabs
CoinGecko free key 365d ~90d hourly altcoins, cross-checks
yfinance no ~10y 730d hourly zero-setup start
ccxt no per-exchange per-exchange multi-venue
CryptoCompare free key 2000+/call histohour deep daily history

The trap people hit first

Not the API — the data hygiene. Whatever source you use, you will hit: mixed timezone conventions (some return ms epoch, some ISO strings), zero-volume rows during outages, and exchange-specific gaps that silently wreck a moving-average backtest. Standardize to a UTC-indexed float DataFrame before any indicator math, and drop rows where volume == 0 and high == low (frozen feed signature).

I packaged the cleaning + backtest loop (the exact functions I use to sanity-check a strategy idea in one evening) into a cheap toolkit — Python Backtest Toolkit — because I got tired of re-writing the same 80 lines every time someone asked. Everything above is doable with the free sources alone; the toolkit just saves you the plumbing.

If you only bookmark one thing here: Binance klines for bulk work, yfinance for the five-minute start.

Top comments (0)