# Needed for adding my version of py_etherscan_api pacakge
import sys
sys.path.append('/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/')
import etherscan.accounts as accounts
import pandas as pd
import json
from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, iplot
from plotly.offline import plot
from plotly.graph_objs import Scatter, Data, Box, Bar
from plotly.graph_objs import Scattergl
init_notebook_mode() # run at the start of every ipython notebook to use plotly.offline
# this injects the plotly.js source files into the notebook
from plotly.tools import FigureFactory as FF
import plotly.plotly as py
import plotly.graph_objs as go
from plotly import tools
%matplotlib inline
import matplotlib as plt
plt.style.use('ggplot')
import cufflinks as cf
cf.set_config_file(offline=True, world_readable=True, theme='ggplot')
IOPub data rate exceeded. The notebook server will temporarily stop sending output to the client in order to avoid crashing it. To change this limit, set the config variable `--NotebookApp.iopub_data_rate_limit`.
with open('../api_key.json', 'r') as key_file:
key = json.loads(key_file.read())['key']
api = accounts.Account(address="0x49EdF201c1E139282643d5e7C6fB0C7219Ad1db7", api_key=key)
transactions = api.get_all_transactions()
df = pd.DataFrame(transactions)
page 1 added Total number of transactions: 2856
df.value = df.value.astype(float)/ 1000000000000000000
df.timeStamp = pd.to_datetime(df.timeStamp, unit='s')
# Check total of successful ETH transactions
df[df.isError == '0'].value.sum()
166710.89379168933
block_df = pd.DataFrame(df[df.isError == 0].groupby('timeStamp').sum().reset_index())
block_df.value_cum = block_df.value.cumsum()
import datetime
dt = datetime.datetime(2017, 5, 2, 15, 30)
dt2 = datetime.datetime(2017, 5, 2, 18, 40)
mask1 = (df.isError == '0') & (df.timeStamp > dt) & (df.timeStamp < dt2)
mask2 = (df.isError == '1') & (df.timeStamp > dt) & (df.timeStamp < dt2)
trace = go.Bar(
x=df[mask1].timeStamp,
y=df[mask1].value,
name="successful",
)
trace2 = go.Bar(
x=df[mask2].timeStamp,
y=df[mask2].value,
name="failed",
)
layout = go.Layout(
xaxis=go.XAxis(
title='Time of Investment',
# titlefont = dict(
# size = 16,
# ),
# tickfont = dict(
# size = 16
# )
),
yaxis=go.YAxis(
title='ETH Invested',
# titlefont = dict(
# size = 16,
# ),
# tickfont = dict(
# size = 16
# )
),
legend = {
'x':0.8,
'y':1
},
# margin={
# 'l': 200,
# 'r': 100,
# 'b': 200,
# },
# height=1500,
# width=3000
# barmode='stack'
)
data = [trace, trace2]
fig = go.Figure(data=data, layout=layout)
iplot(fig)
#py.iplot(fig, filename='TokenCard_TimeSeries_Invested')
combined = df[df.isError == '0'].groupby('from').sum().reset_index()
def label_exp_group(value):
labels = ['0', '1', '2', '3', '4', '5', '6', '7', '8']
for label in labels:
if value <= 10**float(label):
return label
combined['exp_group'] = combined.value.apply(label_exp_group)
grouped = pd.DataFrame(combined.groupby('exp_group').sum())
grouped = grouped[['value']]
grouped_size = pd.DataFrame(combined.groupby('exp_group').size())
grouped['size'] = grouped_size[0].values
grouped['size_perc'] = [trans / len(combined) * 100 for trans in grouped['size'].values]
grouped['value_perc'] = [value / 250000 * 100 for value in grouped.value.values]
grouped
value | size | size_perc | value_perc | |
---|---|---|---|---|
exp_group | ||||
0 | 104.463452 | 157 | 10.842541 | 0.041785 |
1 | 2728.109497 | 530 | 36.602210 | 1.091244 |
2 | 22326.914998 | 593 | 40.953039 | 8.930766 |
3 | 39741.992495 | 141 | 9.737569 | 15.896797 |
4 | 54084.413349 | 25 | 1.726519 | 21.633765 |
5 | 47725.000000 | 2 | 0.138122 | 19.090000 |
trace = go.Bar(
y=grouped.value_perc,
name='Total ETH'
)
trace2 = go.Bar(
y=grouped.size_perc,
name='Addresses',
)
data = Data([trace, trace2])
layout = go.Layout(
xaxis=go.XAxis(
title='Investor Group',
ticktext = [
"$0 < x < 10^0$",
"$10^0 < x < 10^1$",
"$10^1 < x < 10^2$",
"$10^2 < x < 10^3$",
"$10^3 < x < 10^4$",
"$10^4 < x < 10^5$",
"$10^5 < x < 10^6$",
"Exchange"
],
tickvals = [ 0, 1, 2, 3, 4, 5,6 ],
tickfont=dict(
# size=40,
color='black'
),
titlefont=dict(
# size=50,
color='black'
),
),
yaxis=go.YAxis(
title='Percentage',
tickfont=dict(
# size=40,
color='black'
),
titlefont=dict(
# size=50,
color='black'
),
),
legend=dict(
x=0,
y=1,
font=dict(
# size=40,
color='black'
),
),
# height=1500,
# width=3000,
margin={
'b': 100,
},
# barmode='stack'
)
fig = go.Figure(data=data, layout=layout)
# iplot(fig)
py.iplot(fig, filename='TokenCard_investor_percentage_breakdown')
import requests
def get_token_amount(token, address):
req = requests.get(url='https://api.etherscan.io/api?module=account&action=tokenbalance&tokenname='+token+'&address='+address+'&tag=latest&apikey='+key)
try:
print(token, ' amount: ', float(json.loads(req.text)['result'])/1e18)
except:
print('token not available')
address='0x49EdF201c1E139282643d5e7C6fB0C7219Ad1db7'
tokens = ['REP', 'DGD', 'MKR', 'GNT', 'MLN', 'SWT', 'SNGLS']
for token in tokens:
get_token_amount(token, address)
REP amount: 39387.01891213 DGD amount: 2.94466972444e-05 MKR amount: 2.2913320193794133 token not available token not available token not available SNGLS amount: 1.2431534e-11
# ERC20 token amounts given by etherscan.io as of Tues 4:06 PM EST
token_amounts = [
{'token': "REP", 'value': 39387, 'evaluated': 658259.49},
{'token': "DGD", 'value': 29446, 'evaluated': 901672.59},
{'token': "Edgeless", 'value': 1524, 'evaluated': 171.79},
{'token': "Golem", 'value': 1176941, 'evaluated': 265268.49},
{'token': "Guppy", 'value': 5, 'evaluated': 0.79},
{'token': "Melon", 'value': 640, 'evaluated': 24606.91},
{'token': "MKR", 'value': 2, 'evaluated': 200.27},
{'token': "SNGLS", 'value': 12431535, 'evaluated': 1423423.19},
{'token': "SwarmCity", 'value': 300802, 'evaluated': 420356.49},
{'token': "ETH", 'value': 166710, 'evaluated': 13028465.35}
]
token_amounts = pd.DataFrame(token_amounts)
token_amounts = token_amounts[['token', 'value', 'evaluated']]
token_amounts
token | value | evaluated | |
---|---|---|---|
0 | REP | 39387 | 658259.49 |
1 | DGD | 29446 | 901672.59 |
2 | Edgeless | 1524 | 171.79 |
3 | Golem | 1176941 | 265268.49 |
4 | Guppy | 5 | 0.79 |
5 | Melon | 640 | 24606.91 |
6 | MKR | 2 | 200.27 |
7 | SNGLS | 12431535 | 1423423.19 |
8 | SwarmCity | 300802 | 420356.49 |
9 | ETH | 166710 | 13028465.35 |
print(token_amounts.evaluated.sum())
16722425.36
token_amounts[token_amounts.token == 'ETH'].evaluated / token_amounts.evaluated.sum() * 100
9 77.910142 Name: evaluated, dtype: float64
trace = go.Bar(
x=token_amounts.token,
y=token_amounts.evaluated
)
layout = go.Layout(
xaxis=go.XAxis(
title='ERC20 Token',
tickfont=dict(
# size=40,
color='black'
),
titlefont=dict(
# size=50,
color='black'
),
),
yaxis=go.YAxis(
title='USD Amount Invested',
tickfont=dict(
# size=40,
color='black'
),
titlefont=dict(
# size=50,
color='black'
),
),
)
data = [trace]
fig = go.Figure(data=data, layout=layout)
# iplot(fig)
py.iplot(fig, filename='TokenCard_token_breakdown')