After running into Unicode indexing errors in Python 2.7, a solution was found by installing the Anaconda Python 3.4 distribution. This will also set up your System Environment Variables.
This will be an example that shows you an easy way to capture the ticker data from btc-e.com for all currency pairs. HDF5, also known as Hierarchical Data Format, and Pandas DataFrame will demonstrate to be powerful for quick analysis on large data-sets.
After you have installed the distribution, open the Anaconda Launcher:
Launch an ipython-notebook. A new window should open directed towards localhost:8888/tree or similar. Under files go to the new button and select “Python 3” under the notebooks section.
To begin, import pandas and the time library by doing the following:
Also, set a variable named url to be the BTC-e api ticker url. In this instance we are concerned with capturing data for each pair available on BTC-e.
Next will be the soul of our data capturing, pd.read_json() .
I recommend setting the delay to time.sleep(2). If you read the API information on BTC-e, it states that it refreshes at 0.5Hz.
We simply read the json from the api url into a data-frame named frame and transpose it. Next, we define keylist as the values of the index (pair names for ex. ‘btc_usd’ to be used as the data-frame key); of which is accomplished by setting keylist = frame.index.values.
In the for loop we then separate out each pair with its index set to the series ‘updated’. We then use store.append(‘key’,data) to append each key and data-set to pd.HDFStore(‘filename.h5’).
Once you stop the loop, you can view the data with the follow:
Type any pair combination on BTC-e as the key such as ‘ltc_usd’ or ‘ppc_usd’ to get the logged data.
Here’s a quick example of plotting the data.
Next we will learn about real time plotting using matplotlib!