The quick and easy way to get historical data for almost every cryptocurrency, using cryptowat.ch python api, no registration, no keys or fees involved.
Just starting to get into algotrading, and looking for a free data source for historical to near-live data? In this post, you will find out how simple it is to get price data for almost any crypto (Bitcoin, Litecoin, Ether, etc) using a little bit of Python.
Cryptowat.ch is a free service that offers an API to access crypto data. The API is really well documented and the free quota is available. So what data is available via this free API? Any trading pair from these exchanges:
- HitBTC
- FTX
- Coinbase Pro
- Bitstamp
- Kraken
- Bittrex
- Binance
- Gate.io
- Cryptsy
- Vault of Satoshi
- Kraken Futures
- Uniswap V2
- CEX.IO
- BitMEX
- Luno
- Bisq
- WEX
- 796
- Huobi
- BitBay
- FTX.US
- Mt. Gox
- Bit-Z
- DEX (aggregated)
- Quoine
- Liquid
- BitVC
- BTC China
- meXBT
- bitFlyer
- Poloniex
- Bithumb
- Okex
- Coinone
- Deribit
- Bitfinex
- Gemini
- OKCoin
- QuadrigaCX
- Binance.US
You can get all OHLC data for any candle from 1 minute to 1 week, check details in documentation here: docs.cryptowat.ch
First step is to just copy code below, pick what exchange, pair, timeframe, start/end point… and enjoy your data in pandas dataframe ready for analysis.
import pandas as pd
import requests
exchange = 'bitfinex'
pair = 'btcusd'
tf = '4h'
before = '2021-03-01 19:00:00'
after = '2021-02-07 19:00:00'
periods = {"1m": '60',
"3m": '180',
"5m": '300',
"15m": '900',
"30m": '1800',
"1h": '3600',
"2h": '7200',
"4h": '14400',
"6h": '21600',
"12h": '43200',
"1d": '86400',
"3d": '259200',
"1w": '604800'}
period=periods.get(tf)
req = requests.get('https://api.cryptowat.ch/markets/'+exchange+'/'+pair+'/ohlc', params={
'periods': period,
'before': (pd.to_datetime([before]) - pd.Timestamp("1970-01-01")) // pd.Timedelta('1s'),
'after': (pd.to_datetime([after]) - pd.Timestamp("1970-01-01")) // pd.Timedelta('1s')
})
data = req.json()
ohlc = pd.DataFrame(data['result'][period],
columns=['CloseTime',
'OpenPrice',
'HighPrice',
'LowPrice',
'ClosePrice',
'Volume',
'NA'])
ohlc['CloseTime'] = pd.to_datetime(ohlc['CloseTime'], unit='s')
ohlc.drop('NA', axis=1)