Analysing Cryptocurrency Using the Gemini API - Part II

Do repost and rate:

(This is Part II of an ongoing series on how to analyse cryptocurrency trends using Python and the Gemini API - read Part I if you haven't yet!)

So now that you've created your own Gemini account and Gemini sandbox account, you're ready to get your hands on some data to start figuring out important cryptocurrency trends. In Part II of this series, we delve a little dipper into the various "commands" or instruction calls that the Gemini API has, and what kind of data we can obtain.

Data, Datum, Lots of Data!

In summary, you can get the following data via the Gemini API:

  • Cryptocurrency Symbols
  • Ticker Symbols
  • Candles
  • Current Order Books
  • Trade History
  • Current auction
  • Auction history
  • Price feed

Since there's no free lunch in this world, you might be wondering what the catch is? Well, not much that I can figure out at the moment, but these public calls are limited to 120 requests per minute, so it's not as if you can immediately grab all the data you need for data analysis. You might need to do it over the course of a day or two, perhaps.

(Alternatively, you could grab the price data from Yahoo! Finance, but that's a lesson for another day)

Gemini's Coins

The first thing we could do is to pull out a list of coins that Gemini offers on its exchange - so let's start with some basic Python code below. This first chunk of code does four things:

  • A: Imports the necessary libraries and codes for the analysis and calling of Gemini data. Essentially, you will be using the "requests" package to perform the necessary API calls, the "json" package to parse the data that Gemini returns you, and "pandas" to transform the data into nice tables and dataframes for export to Excel
  • B: Setting the base url for all API calls. In short, this address is the web address from which you'll be accessing the Gemini database.
  • C: Calling for cryptocurrency symbols. Basically a command to tell Gemini to send you a list of all the symbols of coins they offer on their exchange
  • D: Displaying the symbols. Self-explanatory, really - but the ".head()" method attached at the end tells Python to extract only the first five symbols in the list for you to view
## A: Importing packages & libraries...import json, requestsimport pandas as pd ## B: Setting base url for all API calls...base_url = "https://api.gemini.com/v2"## C: Calling for symbols...sym_resp = requests.get(base_url + "/symbols")symbols = pd.DataFrame(sym_resp.json())## D: Displaying the first five symbols...symbols.head()

When you are done executing the "symbols.head()" call in Python, you should get a list of the first 5 symbols offered by Gemini:

Quite self-explanatory, again, essentially these are the symbols that correspond to the prices of BTC in USD, GUSD, DAI, GBP and EUR respectively.

Diving Deeper into BTC

Suppose we want to find out more about BTC in USD, we then perform a call using this specific symbol: 

## E: Calling for btcusd info...btcusd_response = requests.get(base_url + "/symbols/details/BTCUSD")btcusd = btcusd_response.json()## F: Displaying btcusd info...btcusd

Correspondingly, the last execution should give you the underlying info behind the btcusd cryptocurrency symbol:

Nothing too useful at the moment for the trader - so we push on and call for btcusd prices at 15 minute intervals. However, this time we want to save the output to an Excel file so we can examine the data in greater detail:

## G: Calling for 15 min btcusd prices...prices_15m_resp = requests.get(base_url + "/candles/btcusd/15m")## H: Creating a "btc_prices" dataframe to store the price data...btc_prices = pd.DataFrame(prices_15m_resp.json(), columns =['time','open','high','low','close','volume'])## I: Setting time-units and sorting the prices by time...btc_prices['time'] = pd.to_datetime(btc_prices['time'], unit='ms')btc_prices.set_index('time', inplace=True)btc_prices.sort_values(by =['time'], inplace = True)## J: Displaying 15 min btcusd prices...btc_prices## K: Saving "btc_prices" to an Excel file...btc_prices.to_excel("btc_prices.xlsx")

Go to the directory where you ran your Python program and you'll find the "btc_prices.xlsx" file ready for exploring - the data goes back to the last 14 days when you call the default commands like this. So this Excel file essentially contains the prices of BTC in USD every 15 minutes from the time you generated the file going back to the last 14 days.

Suppose you want to call for BTC prices in 1-day intervals instead, then you could tweak the time unit from "15m" to "1d":

## G: Calling for 1 day btcusd prices...prices_1d_resp = requests.get(base_url + "/candles/btcusd/1day")## H: Creating a "btc_prices" dataframe to store the price data...btc_prices = pd.DataFrame(prices_1d_resp.json(), columns =['time','open','high','low','close','volume'])## I: Setting time-units and sorting the prices by time...btc_prices['time'] = pd.to_datetime(btc_prices['time'], unit='ms')btc_prices.set_index('time', inplace=True)btc_prices.sort_values(by =['time'], inplace = True)## J: Displaying 1 day btcusd prices...btc_prices## K: Saving "btc_prices" to an Excel file...btc_prices.to_excel("btc_prices.xlsx")

This should update your Excel file to 1 day interval prices. In this case, the data goes back to the last 365 days when you call the default commands like this. So this Excel file essentially contains the prices of BTC in USD every 15 minutes from the time you generated the file going back to the last 365 days.

And there you go! You've performed your first data call, and you've a truckload of data now to work with. We could theoretically repeat the calls above to obtain the past 1 year data for BTC, ETH and any coin of your choice really, and that should give you the necessary data to work with.

Check back next post for how to generate key technical analysis indicators. Eventually, we'll move into simulating an investing strategy of your choice, and examine the efficacy of a few archetypes.

 

Regulation and Society adoption

Ждем новостей

Нет новых страниц

Следующая новость