The purpose of this project is to create a tool for analysing crypto prices BEYOND what is provided by Coinmarketcap but using Coinmarketcap (CMC ) data. CMC allows you to view the hourly, daily and weekly price changes for every coin as well as viewing the historic price/volume on a graph. While this is very useful I believe there are many more valuable metrics which could be offered by utilizing the data available on CMC, for example:
The key purpose of this project is to create a dashboard which will allow various statistics to be produced on CMC data. For example, you will be able to calculate the price change over specified periods of time (as opposed to last hour/day etc.) and extract other useful statistics such as the highest and lowest prices, the growth relative to other currencies i.e. Steem/SBD, and how correlated the currency is with bitcoin or other coins of interest.
Another key purpose of the project is to allow users to generate graphs and upload them to drop-box so they can include them in Steemit posts (see code below).
In addition, I intend to add the ability to download specified historical data from Coinmarketcap. Historic data is currently available from CMC using the link https://graphs2.coinmarketcap.com/currencies/steem/. This is the link for Steem; every currency has it's own link i.e. ripple is https://graphs2.coinmarketcap.com/currencies/ripple/
As you can see from the link (and the screenshot below), the data is in json format:
The data includes daily price (in BTC and USD) and volume for every coin going back as far as the coin started trading on one of the main exchanges.
I plan to create a simple and accessible way of downloading any currency's historic data to a csv so that analysts can play around with the data and produce their own study of the prices and trends.
So, in summary, this project will hopefully provide a useful a add-on to Coinmarketcap which I feel will fill some gaps in the scope of analytics available to those interested in studying trends and statistics around cryptocurrencies.
I have begun writing the code to extract data from coinmarketcap, which is saved in the project GitHub repository (statsmonkey1/statsmonkey) in the file coinmarketcap.py.
The key parts of the code written so far are outline below:
Output folder location where graphs are stored before uploading to dropbox
output_folder = "C:/steemit/Plots/"
Which currency to create the report for
currency = "steem"
Dropbox access token to upload/host graphs from dropbox
dropbox_access_token = 'xxxxxxx'
dropbox_access_token = 'xxxxxxx'
Parameters for RSI respectively
RSI_PERIOD = 14
OVERBOUGHT = 70
OVERSOLD = 30
MIDDLE = 50
Indicate range of data for analysis. e.g. 40 = last 40 days of data
data_window = 40
Email details (when error)
from_email = "[email protected]"
from_pswd = "password"
to_email = "[email protected]"
Grab data from coinmarketcap
try: # Try pulling data from coinmarketcap
link = 'https://graphs2.coinmarketcap.com/currencies/' + currency
df = pd.DataFrame(requests.get(link).json())
df2 = pd.concat([pd.DataFrame([x for x in df[df.columns[y]]], columns = ['Date', df.columns[y]]).set_index('Date', drop = True) for y in range(len(df.columns))],axis = 1)
df2.index = pd.to_datetime(df2.index, unit = 'ms').date
df2 = df2[~df2.index.duplicated(keep='first')]
except: # If the above fails, send a notification email
body_ = "Error pulling market data from coinmarketcap.com. Try going to " + link + " to see if any data appears"
emailer(currency, body_, from_email, from_pswd, to_email)
sys.exit()
Do calculations to get Relative Strength Index (RSI)etc.
try: # Try doing calculations for plots
RSI_ALPHA = 1/RSI_PERIOD
RSI_1_ALPHA = 1-RSI_ALPHA
df2['d_price'] = df2['price_usd'] - df2['price_usd'].shift()
df2['U'] = df2[df2['d_price']>0]['d_price']
df2['U'] = df2['U'].replace(np.nan, 0)
df2['D'] = -df2[df2['d_price']<0]['d_price']
df2['D'] = df2['D'].replace(np.nan, 0)
df2.ix[df2.index[0], 'SMMA_U'] = 0
df2.ix[df2.index[0], 'SMMA_D'] = 0
for x in df2.index[1:]:
df2.ix[x, 'SMMA_U'] = RSI_ALPHA*df2.ix[x,'U'] + RSI_1_ALPHA*df2.shift().ix[x,'SMMA_U']
df2.ix[x, 'SMMA_D'] = RSI_ALPHA*df2.ix[x,'D'] + RSI_1_ALPHA*df2.shift().ix[x,'SMMA_D']
df2['RS'] = df2['SMMA_U']/df2['SMMA_D']
df2['RSI'] = 100 - (100/(1+df2['RS']))
df2['OVERBOUGHT'] = OVERBOUGHT
df2['OVERSOLD'] = OVERSOLD
df2['MIDDLE'] = MIDDLE
Error Email
except: # Send email if above fails
body_ = "An error occured conducting calculations for charts. That data is reading in correctly."
emailer(currency, body_, from_email, from_pswd, to_email)
sys.exit()
Create RSI Graphs
RSI_PLOT, ax = plt.subplots(2, figsize = (12,8))
ax[0].plot(df3['price_usd'], alpha = 0.7, lw = 2.0, label = currency + " price (USD)")
ax[1].plot(df3['RSI'], alpha = 0.7, lw = 2.0, label = 'RSI', color = 'r')
ax[1].plot(df3['OVERBOUGHT'], alpha = 0.7, lw = 2.0, label = 'Overbought(70)', ls = "--", color = 'k')
ax[1].plot(df3['MIDDLE'], alpha = 0.7, lw = 2.0, label = 'Middle(50)', color = 'k')
ax[1].plot(df3['OVERSOLD'], alpha = 0.7, lw = 2.0, label = 'Undersold(30)', ls = "--", color = 'k')
for x in ax:
x.spines['right'].set_color('none')
x.spines['top'].set_color('none')
ax[1].spines['bottom'].set_position('zero')
ax[1].axes.get_xaxis().set_visible(False)
ax[0].set_xticklabels(ax[0].xaxis.get_majorticklabels(), rotation=30)
myFmt = mdates.DateFormatter('%m/%d/%y')
ax[0].xaxis.set_major_formatter(myFmt)
ax[0].xaxis.set_ticks_position('bottom')
ax[0].yaxis.set_ticks_position('left')
ax[1].yaxis.set_ticks_position('left')
ax[0].legend(loc=2)
ax[1].legend(loc=3, ncol = 4)
ax[1].set_ylim([0,100])
Function to save graphs to dropbox
def write_to_dropbox(file_from, access_token):
dbx = dropbox.Dropbox(access_token)
file_to = '/graphs/' + file_from.split("/")[-1]
with open(file_from, 'rb') as f:
dbx.files_upload(f.read(), file_to)
url = dbx.sharing_create_shared_link(file_to).url
url = url.replace(r"?dl=0", "?dl=1")
return url
try:
RSI_url = write_to_dropbox(RSI_file_from, dropbox_access_token)
except:
body_ = "An error occured when outputing the files to dropbox. Check to make sure internet is working."
emailer(currency, body_, from_email, from_pswd, to_email)
sys.exit()
The next step is to create a URL with a basic prototype. I hope to have this in the next week as a key challenge was extracting the data from coinmarketcap (which is now done).
I would really like to hear your feedback on the proposal and plan for this project.
Cover picture source: Pixabay