Profile picture

Co-founder @ RMOTR

Bitcoincharts API Live Docs

Last updated: December 6th, 20182018-12-06Project preview

This quick interactive guide will show you how Bitcoinchart's API works. Bitcoinchart offers a free non-authenticated API to acccess Bitcoin prices.

Important! Bitcoincharts only offers Bitcoin data (doh!), for other cryptos see my other post about Cryptowatch API.

Bitcoincharts also offers historic data as complete CSVs, that you can just download as regular files: http://api.bitcoincharts.com/v1/csv/. Warning, files are large.

Let's get started with the most important endpoints:

In [1]:
import requests
from io import StringIO
import pandas as pd

%matplotlib inline

Weighted Prices

Weighted Prices offers a "summary" of the price of Bitcoin for different fiat currencies (US Dollars, Euros, etc).

In [2]:
resp = requests.get('http://api.bitcoincharts.com/v1/weighted_prices.json')
In [3]:
resp
Out[3]:
<Response [200]>
In [4]:
resp.json()
Out[4]:
{'USD': {'7d': '4068.50', '30d': '4569.24', '24h': '3882.95'},
 'NGN': {'7d': '1483421.77', '30d': '1731965.58', '24h': '1420214.99'},
 'IDR': {'7d': '59409992.40', '30d': '67819517.46', '24h': '56758044.48'},
 'ILS': {'7d': '15168.79', '30d': '17026.64', '24h': '14387.42'},
 'GBP': {'7d': '3224.89', '30d': '3844.23', '24h': '3075.52'},
 'DKK': {'7d': '31215.22', '30d': '38373.84', '24h': '28783.95'},
 'AUD': {'7d': '5527.97', '30d': '6352.93', '24h': '5324.03'},
 'PKR': {'7d': '796900.82', '30d': '758251.27'},
 'JPY': {'7d': '460745.19', '30d': '531302.30', '24h': '436609.84'},
 'VND': {'7d': '95983459.48', '30d': '111560533.53', '24h': '88784169.36'},
 'MYR': {'7d': '6361.81', '30d': '8886.08', '24h': '6182.15'},
 'CAD': {'7d': '5387.83', '30d': '6166.75', '24h': '5204.61'},
 'SEK': {'7d': '39986.45', '30d': '46607.71', '24h': '38306.99'},
 'SGD': {'7d': '5588.02', '30d': '6460.89', '24h': '5438.26'},
 'HKD': {'7d': '31655.97', '30d': '39710.15', '24h': '30115.29'},
 'VES': {'7d': '1971522.21', '30d': '1719801.61', '24h': '1990605.14'},
 'CHF': {'7d': '4481.27', '30d': '5124.88', '24h': '4394.73'},
 'timestamp': 1544022908,
 'KRW': {'7d': '4637596.35', '30d': '5418266.86', '24h': '4395215.28'},
 'VEF': {'30d': '35875760927.63'},
 'NZD': {'7d': '6010.26', '30d': '7284.34', '24h': '5912.50'},
 'CLP': {'7d': '2750120.41', '30d': '3528156.66', '24h': '2684451.03'},
 'THB': {'7d': '131023.57', '30d': '155296.13', '24h': '125725.83'},
 'EUR': {'7d': '3581.96', '30d': '4108.91', '24h': '3414.42'},
 'ARS': {'7d': '157846.76', '30d': '186476.64', '24h': '151628.98'},
 'NOK': {'7d': '36140.21', '30d': '43878.08', '24h': '34686.12'},
 'RUB': {'7d': '286002.91', '30d': '340254.53', '24h': '270020.91'},
 'INR': {'7d': '307686.53', '30d': '390065.63', '24h': '294792.57'},
 'MXN': {'7d': '84302.91', '30d': '104769.97', '24h': '81088.82'},
 'CZK': {'7d': '93292.79', '30d': '115272.33', '24h': '85556.20'},
 'BRL': {'7d': '15896.67', '30d': '18129.89', '24h': '15165.68'},
 'PLN': {'7d': '15438.18', '30d': '17462.84', '24h': '14688.53'},
 'ZAR': {'7d': '58745.96', '30d': '70159.43', '24h': '55809.27'}}

This endpoint is probably not so useful, as aggregated price data isn't really actionable. The next ones, Markets Data and Historic Trade Data are more interesting.

Markets Data

Markets Data offers current market prices for multiple exchanges and fiat currencies (US Dollars, Euros). It's a snapshot of the current market for that particular exchange.

In [5]:
resp = requests.get('http://api.bitcoincharts.com/v1/markets.json')
In [6]:
resp
Out[6]:
<Response [200]>
In [8]:
doc = resp.json()
In [11]:
print(f"There are {len(doc)} results")
There are 260 results

An example of one of the results:

In [9]:
doc[0]
Out[9]:
{'currency': 'USD',
 'high': 35999.71,
 'latest_trade': 1544022155,
 'weighted_price': 4199.361229184757,
 'bid': 52618.78,
 'volume': 309.58369603,
 'ask': 3619.12,
 'low': 2890.6,
 'duration': 91081,
 'close': 4003.89,
 'avg': 4199.361229184757,
 'symbol': 'localbtcUSD',
 'currency_volume': 1300053.770296101}

For example, here are the results for Bitstamp:

In [10]:
[d for d in doc if 'bitstamp' in d['symbol'].lower()]
Out[10]:
[{'currency': 'USD',
  'high': 4033.98,
  'latest_trade': 1544023073,
  'weighted_price': 3873.830444518836,
  'bid': 3821.8,
  'volume': 11310.48085126,
  'ask': 3824.63,
  'low': 3774.73,
  'duration': 91082,
  'close': 3826.99,
  'avg': 3873.8304445188355,
  'symbol': 'bitstampUSD',
  'currency_volume': 43814885.063758306},
 {'currency': 'EUR',
  'high': 3560.68,
  'latest_trade': 1544023080,
  'weighted_price': 3436.3240872852516,
  'bid': 3376.24,
  'volume': 2161.24470408,
  'ask': 3383.85,
  'low': 3317.9,
  'duration': 91089,
  'close': 3376.24,
  'avg': 3436.3240872852534,
  'symbol': 'bitstampEUR',
  'currency_volume': 7426737.235147794}]

Historic Trade Data

This endpoint returns historic data

In [12]:
resp = requests.get('http://api.bitcoincharts.com/v1/trades.csv', params={
    'symbol': 'bitstampUSD'
})
In [13]:
resp
Out[13]:
<Response [200]>

This endpoint is not JSON data. It's CSV, so the response will look something like:

In [19]:
print(resp.text[:90])
1544023320,3824.170000000000,0.059921830000
1544023304,3825.110000000000,0.033412000000
15

We can use Pandas to parse this data as a DataFrame:

In [26]:
pd.to_datetime(1544023320)
Out[26]:
Timestamp('1970-01-01 00:00:01.544023320')
In [30]:
df = pd.read_csv(StringIO(resp.text), header=None, names=['Timestamp', 'Price', 'Amount'])
df['Timestamp'] = pd.to_datetime(df['Timestamp'], unit='s')
df.set_index('Timestamp', inplace=True)

These are the first prices:

In [31]:
df.head()
Out[31]:
Price Amount
Timestamp
2018-12-05 15:22:00 3824.17 0.059922
2018-12-05 15:21:44 3825.11 0.033412
2018-12-05 15:21:28 3824.17 0.185208
2018-12-05 15:21:06 3824.10 0.087114
2018-12-05 15:21:04 3824.10 0.912886

Starting on:

In [34]:
df.index.min()
Out[34]:
Timestamp('2018-12-04 06:44:08')

Up to:

In [35]:
df.index.max()
Out[35]:
Timestamp('2018-12-05 15:22:00')

And this is the full chart displaying it the price:

In [29]:
df['Price'].plot(figsize=(14, 7))
Out[29]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fb1c5ec85c0>
Notebooks AI
Notebooks AI Profile20060