This is a simple "Blockfolio" using Python and the CoinMarketCap API.
It will show the net worth in USD of your Cryptocurrency investments as well as the relative share of coins you own in comparison to the total coin supply of the corresponding digital asset.
First, the current exchanges rates are loaded, then combined with your investments, and finally displayed using Plotly.
This notebook can be found on my github profile.
import pandas as pd
import plotly.offline as py
import plotly.graph_objs as go
py.init_notebook_mode(connected=True)
limit = 200 # only load the top 200 currencies, if you have invested in smaller ones increase this limit
coin_market_cap_api = 'https://api.coinmarketcap.com/v1/ticker/?limit={}'.format(limit)
coin_market_cap_api
# load the data using pandas and keep track of the time
now = pd.datetime.now()
market_data = pd.read_json(coin_market_cap_api)
market_data.head(10)
Below you can fill in the types and amount of coins you have into the Python dictionary
with the format 'SYMBOL': value
.
# enter your coins below:
block_folio = {
'BTC': 0.31337,
'BCH': 0.01337,
'ETH': 3,
'LTC': 1.5,
'MIOTA': 777,
'XRP': 13,
'DASH': 0.1,
'XMR': 1,
'LSK': 12,
'OMG': 1.1,
'XRB': 42,
'PIVX': 123,
'ARK': 22,
'NEO': 7,
'GAS': 0.01,
'STEEM': 499,
}
# display your blockfolio
block_folio = pd.DataFrame(list(block_folio.items()), columns=['symbol', 'amount'])
block_folio.head(len(block_folio))
# merge the API and blockfolio data and sort by investment value
merged_data = block_folio.merge(market_data, how='left')
merged_data['value_usd'] = merged_data.amount * merged_data.price_usd
merged_data['coinshare'] = merged_data.amount / merged_data.available_supply
merged_data = merged_data.sort_values('value_usd', ascending=False)
merged_data.head()
networth = 'Your blockfolio is currently (i.e {}) worth {:.2f} USD!'.format(now.strftime('%Y-%m-%d %I:%M %p'),
merged_data.value_usd.sum())
print(networth)
Let's plot the worth of each asset in descending order:
marker = dict(color='rgb(158,202,225)',
line=dict(color='rgb(8,48,107)', width=1.5))
layout = go.Layout(title='Blockfolio Networth in USD',
xaxis=dict(title='Cryptocurrency'),
yaxis=dict(title='USD'))
value_chart=go.Bar(x=merged_data.symbol, y=merged_data.value_usd, marker=marker)
fig = go.Figure(data=[value_chart], layout=layout)
py.iplot(fig)
Finally, that looks at the relative sizes of your investment. This gives you an idea or visualizes in which cryptocurrency you believe in the most. The graph below shows you fractional share of the the current crypto's total supply.
marker = dict(color='rgb(258,202,125)', line=dict(color='rgb(8,48,107)', width=1.5,))
layout = go.Layout(title='Relative Blockfolio Size',
xaxis=dict(title='Cryptocurrency'),
yaxis=dict(title='Fraction of total Supply'))
share_chart=go.Bar(x=merged_data.symbol, y=merged_data.coinshare, marker=marker)
fig = go.Figure(data=[share_chart], layout=layout)
py.iplot(fig)