import pandas as pd
import plotlyink
import plotly
plotly.offline.init_notebook_mode(connected=True)
base_polo_url = 'https://poloniex.com/public?command=returnChartData¤cyPair={}&start={}&end={}&period={}'
start_date = pd.Timestamp('2018-01-01', tz='CET')
end_date = pd.Timestamp('2018-02-01', tz='CET')
period = 86400 # pull daily data (86,400 seconds per day)
def get_crypto_data(poloniex_pair):
'''Retrieve cryptocurrency data from poloniex'''
json_url = base_polo_url.format(poloniex_pair, start_date.timestamp(), end_date.timestamp(), period)
df = pd.read_json(json_url)
return df.set_index('date')
altcoins = ['ETH','LTC','XRP','ETC','STR','DASH','SC','XMR','XEM']
dfs = []
for altcoin in altcoins:
coinpair = 'BTC_{}'.format(altcoin)
crypto_price_df = get_crypto_data(coinpair)[['weightedAverage']]
dfs.append(crypto_price_df.rename(columns={'weightedAverage': coinpair}))
df = pd.concat(dfs, axis=1)
df.head()
BTC_ETH | BTC_LTC | BTC_XRP | BTC_ETC | BTC_STR | BTC_DASH | BTC_SC | BTC_XMR | BTC_XEM | |
---|---|---|---|---|---|---|---|---|---|
date | |||||||||
2018-01-01 | 0.055675 | 0.016723 | 0.000145 | 0.002194 | 0.000033 | 0.075174 | 0.000002 | 0.024788 | 0.000076 |
2018-01-02 | 0.060632 | 0.017649 | 0.000147 | 0.002258 | 0.000037 | 0.078409 | 0.000002 | 0.025384 | 0.000077 |
2018-01-03 | 0.059944 | 0.016570 | 0.000171 | 0.002121 | 0.000051 | 0.074916 | 0.000002 | 0.025083 | 0.000094 |
2018-01-04 | 0.064191 | 0.015864 | 0.000199 | 0.002334 | 0.000053 | 0.075819 | 0.000003 | 0.025095 | 0.000123 |
2018-01-05 | 0.062074 | 0.015331 | 0.000165 | 0.002104 | 0.000041 | 0.070231 | 0.000003 | 0.022440 | 0.000103 |
df.iplot.scatter() # is the same as: df.iplot.scatter.lines() or as df.iplot.scatter(mode='line')
df.iplot.scatter(colors='rdylgn') # 'spectral' is the default
df.iplot.scatter(colors='rdylgn', ncolors=11) # cf colors for more details
df.iplot.scatter(colors='spectral', ncolors=11, filter_brightness=False) # A filter for too bright colors is applyed by default
df.iplot.scatter.markers()
df.iplot.scatter.area() # fill 'tonexty'
df.iplot.bar()
df.iplot.bar(barmode='stack')
df.iplot.correlation_matrix()
import numpy as np
# Adding some NaNs values:
lowerbound = (start_date + pd.Timedelta(days=4)).strftime('%Y-%m-%d')
upperbound = (end_date - pd.Timedelta(days=12)).strftime('%Y-%m-%d')
df.loc[(df.index > lowerbound ) & (df.index < upperbound), ['BTC_ETC', 'BTC_XRP']] = np.nan
df.iplot.missing_values()