PART 2.1: Plotting BTC-e API Data in Matlab

This next tutorial will guide you through how to get nice, clean, and readable plots out of Matlab. The data that you have fetched with the API and have stored, will be plotted so you can have a view of what everything looks like while double checking that your code is working correctly.

Please note that there are many ways to do what I’m about to show you, this is one way that i find simple and easy to follow.

From this point, we will assume that you have completed the Capturing Data for each pair that you are monitoring. Your code may look similar to mine if you followed the Part 2: Matlab Data Collection. I have added a couple lines of code at the end of each fetching round for user feed back in the console output. This is not necessary but I like it for Debugging and its nice to see where the code is if matlab is working.

Ticker_Grabber Loop

Note: My current if statement will allow the Ticker_Grabber to run 40 rounds, there are some issues with the workspace data getting updated in between rounds. We are working on forcing the data to update in the workspace for live plots. (Simulink may be the answer or we might integrate matlab with python.)

Anyways, as you can see the Ticker_Grabber is fetching the order books history for the following pairs: BTC-USD, LTC-USD, LTC-BTC, and PPC-USD. You can add the code for all the other pairs on BTC-e to compare all markets. I will keep it simple for this example but remember that this can be scaled up for all order pairs.

We want to make note of the .mat files that we are creating for each of the pairs. In my case in the btc_usd_orderBook.m will output two .mat files. One for Bidding and one for Asking. If you are not getting two .mat files for each order pair, please visit the Part 2 – Data Capture for more info. For each order pair, you should have two .mat files to work with. In my case I will have a total of 8 .mat files to plot.

For my purposes, I will be plotting the price and volume separate for each asking and bidding strings. You can however get asking and bidding plots on one graph for comparison, but may not be super clear what is going on. Also, keeping the data separate will allow us to use some data manipulation functions later.

Ticker_Grabber Plot code 1Using the figure() command we can group the graphs for each pair and combine them with the subplot to make a nice 2×2 graph. This line of code above is fetching all the values for the asking price of BTC_USD and plotting them against the time stamp of the BTC-e server.

Ticker_Grabber Plot code 2

Subplot 2 is very similar to the code of the asking price, but now we are fetching the volume and plotting those values also against the server time. Be sure to make clear labels for your graphs, that way you can really keep track of what is being displayed. Moving right along.

Ticker_Grabber Plot code 3

By now you should be getting the hang of what is going on here. Pay attention to the numbering of the subplot function. There is more info on the how the subplot works if you type ‘doc subplot’ in the workspace. For what we are doing this will work just fine. If you have done everything correctly your plots should come out as shown below. You can tweak the color and line art with a little more code. The next pair for plotting will start with the figure(2) and repeat the steps above.

Ticker_Grabber Plot

I hope you have found this post interesting and helpful! If you need any assistance please feel free to contact us. Join us in the Mumble server for live trading advice or bot building help!

Thanks All!

Mr.Wong

One thought on “PART 2.1: Plotting BTC-e API Data in Matlab

if you have any questions or concerns feel free to ask away!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s