4.3 Active Addresses
The plot on the bottom of this page provides visualization of the total number of addresses that have been active on a daily basis for each of the three cryptocurrencies.
The whole process of acquiring the data is shown bellow. Clicking the toggle buttons expands each part of the code.
from google.cloud import bigquery
from google.oauth2 import service_account
import plotly.graph_objects as go
import plotly.tools as tls
from plotly.offline import plot, iplot, init_notebook_mode
from IPython.core.display import display, HTML
init_notebook_mode(connected = True)
config={'showLink': False, 'displayModeBar': False}
credentials = service_account.Credentials.from_service_account_file(
'cred.json')
project_id = 'intricate-yew-283611'
client = bigquery.Client(credentials= credentials,project=project_id)
Bitcoin
The following query (click the toggle button to expand the code) outputs the number of active Bitcoin addresses for each day
query_job1 = client.query("""
with cte as(SELECT block_timestamp, ARRAY_TO_STRING(addresses, ',') as addresses
FROM `bigquery-public-data.crypto_bitcoin.transactions`,UNNEST(outputs) as ins
UNION ALL
SELECT block_timestamp, ARRAY_TO_STRING(addresses, ',') as addresses
FROM `bigquery-public-data.crypto_bitcoin.transactions`,UNNEST(inputs) as ins)
select EXTRACT(DAY FROM block_timestamp) as Day,
EXTRACT(MONTH FROM block_timestamp) as Month ,
EXTRACT(YEAR FROM block_timestamp) as Year,
concat(Cast(EXTRACT(YEAR FROM block_timestamp) as String),'-',Cast(EXTRACT(MONTH FROM block_timestamp) as String),'-',Cast(EXTRACT(DAY FROM block_timestamp) as String)) as Datum,
COUNT(DISTINCT(addresses)) as distinct_addresses
from cte
group by Year,Month, Day, Datum
order by Year, Month, Day
""")
results1 = query_job1.result()
bitcoin_df = results1.to_dataframe()
print(bitcoin_df)
Bitcoin Cash
The following query (click the toggle button to expand the code) outputs the number of active Bitcoin Cash addresses for each day
query_job2 = client.query("""
with cte as(SELECT block_timestamp, ARRAY_TO_STRING(addresses, ',') as addresses
FROM `bigquery-public-data.crypto_bitcoin_cash.transactions`,UNNEST(outputs) as ins
UNION ALL
SELECT block_timestamp, ARRAY_TO_STRING(addresses, ',') as addresses
FROM `bigquery-public-data.crypto_bitcoin_cash.transactions`,UNNEST(inputs) as ins)
select EXTRACT(DAY FROM block_timestamp) as Day,
EXTRACT(MONTH FROM block_timestamp) as Month ,
EXTRACT(YEAR FROM block_timestamp) as Year,
concat(Cast(EXTRACT(YEAR FROM block_timestamp) as String),'-',Cast(EXTRACT(MONTH FROM block_timestamp) as String),'-',Cast(EXTRACT(DAY FROM block_timestamp) as String)) as Datum,
COUNT(DISTINCT(addresses)) as distinct_addresses
from cte
group by Year,Month, Day, Datum
order by Year, Month, Day
""")
results2 = query_job2.result()
cash_df = results2.to_dataframe()
print(cash_df)
Litecoin
The following query (click the toggle button to expand the code) outputs the number of active Litecoin addresses for each day
query_job = client.query("""
with cte as(SELECT block_timestamp, ARRAY_TO_STRING(addresses, ',') as addresses
FROM `bigquery-public-data.crypto_litecoin.transactions`,UNNEST(outputs) as ins
UNION ALL
SELECT block_timestamp, ARRAY_TO_STRING(addresses, ',') as addresses
FROM `bigquery-public-data.crypto_litecoin.transactions`,UNNEST(inputs) as ins)
select EXTRACT(DAY FROM block_timestamp) as Day,
EXTRACT(MONTH FROM block_timestamp) as Month ,
EXTRACT(YEAR FROM block_timestamp) as Year,
concat(Cast(EXTRACT(YEAR FROM block_timestamp) as String),'-',Cast(EXTRACT(MONTH FROM block_timestamp) as String),'-',Cast(EXTRACT(DAY FROM block_timestamp) as String)) as Datum,
COUNT(DISTINCT(addresses)) as distinct_addresses
from cte
group by Year,Month, Day, Datum
order by Year, Month, Day
""")
results = query_job.result()
lite_df = results.to_dataframe()
print(lite_df)
fig3 = go.Figure()
fig3.add_trace(go.Scatter(x = bitcoin_df['Datum'], y = bitcoin_df['distinct_addresses'],name = 'Bitcoin'))
fig3.add_trace(go.Scatter(x = cash_df['Datum'], y = cash_df['distinct_addresses'], name = 'Bitcoin Cash'))
fig3.add_trace(go.Scatter(x = lite_df['Datum'], y = lite_df['distinct_addresses'], name = 'Litecoin', line = dict(color = 'Light Green')))
fig3.update_layout(paper_bgcolor = 'White',xaxis_title="Date",
yaxis_title='Number of active addresses',plot_bgcolor="#FFFFFF", hovermode="x",
hoverdistance=100,
spikedistance=1000,
)
fig3.update_xaxes(showspikes=True,spikethickness=2,
spikedash="dot",
spikecolor="#999999",
spikemode="across",showgrid=False,ticks = 'outside', showline=True, linecolor='black',rangeslider_visible=True,
rangeselector=dict(
buttons=list([
dict(count=1, label="1m", step="month", stepmode="backward"),
dict(count=6, label="6m", step="month", stepmode="backward"),
dict(count=1, label="YTD", step="year", stepmode="todate"),
dict(count=1, label="1y", step="year", stepmode="backward"),
dict(step="all")
])
))
fig3.update_yaxes(autorange = True, fixedrange= False,showgrid=False, ticks = 'outside', showline=True, linecolor='black')
plot(fig3, filename = 'fig3.html', config = config)
#ThebeLab
display(HTML('fig3.html'))