CLI Project – Bitcoin.com Crypto API

For this project, I wanted to create something that could potentially be useful. The subject of algotrading is really interesting to me, and since the world of cryptocurrency is smaller than the stock market, I decided to apply it to that. Since the overall volume is lower, it’s easier to take advantage of something called arbitrage trading, which takes advantage of the price ‘lag’ between two exchanges. For this project, I started with the Bitcoin.com exchange, hence the project’s name. My end goal is to include other exchanges to monitor and enable trading, but for now, it just gets market data and allows you to check your balance if you have an account.

The gem is published to rubygems.org here: https://rubygems.org/gems/bitcoin-api

  • Install using gem install bitcoin-api
  • In irb, require 'bitcoin', then type Bitcoin::CLI.new to start the CLI, taking us to the main menu.
  • The main menu has three options. Option 3 allows the user to select from a list of currency pairs and view a live ticker.

You can continue making selections to view other Tickers, or press ‘0’ to go back to the main menu. ‘[2] View Currency Menu’ is similar, also one level deep, and allows you to view info on each Currency supported in the exchange.

From the Main Menu, ‘[1] Select Symbol’ allows you to select a currency pair, and takes you to the Symbol Menu. For now, when you enter the Symbol Menu after making a selection, there are a few options:

  • Options 1 and 3 list the 1000 most recent Trades and Candles (OHLC chart)
  • Option 2 lists the current Order Book for this currency pair (BTCUSD in the example), on this exchange.

‘[4] Analysis Mode’ allows you to input a date/time range manually, and view Trades from within that time period. Future versions will allow this for Candles as well. Since the method that handles this can also accept datetimes as arguments, it to be adapted into more advanced analysis methods.

The most challenging part of this project was starting out and not knowing exactly how to structure it. Eventually I realized that it was best to start modeling Classes after the API responses themselves, for example, a Currency. This did present one problem when getting an OrderBook, because the response returned a hash of two separate arrays. I had to figure out how to save each Order instance, while keeping them aware of the hash they came from.

Right now, the methods are mainly focused on displaying the attributes to the user. I expect having to be better with the values the methods are returning rather than just displaying properties. Also, as the project got bigger, I noticed that the Classes had similar methods, so I’m thinking I can refactor them in some way, most of all the self.all methods. I factored out the puts in all of the menu displays, because it started to get very cumbersome. I think it may even help to create a new name space for the cli, and divide the menus into different files pertaining to what they are dealing with.

Although the end result is kind of boring, the project was a lot of fun to work on, and I look forward to expanding on it using other APIs from multiple different exchanges. I hope that it may become a useful tool for someone looking to perform technical analysis on various cryptocurrencies and markets.

Leave a comment

Design a site like this with WordPress.com
Get started