Monday, May 22, 2017

Cryptocurrency Arbitrage

Cryptocurrencies have caught fire in recent months as several governments including Japan, China and Russia, have recently announced recognition of Bitcoin, the macdaddy of blockchain currencies. Other relevant events driving interest in fiat alternatives include the Trump presidency and uncertainty it has introduced in traditional markets, announcements by more and more businesses such as this one by Alzi that they are accepting the currency as a form of payment.

tl;dr A free tool to help cryptocurrency enthusiasts discover BTC and ETH arbitrage opportunities between 2 popular bitcoin exchanges (Gemini and GDAX). Download

Most recently, the value of Bitcoin and related currencies such as Ethereum has skyrocketed, surging nearly 100% in 60 days.



Clearly past performance is no indication of future gain and interested investors would do well to acquaint themselves thoroughly with the technology.  Bitcoin's recent history notwithstanding, the assets value is subject to extreme volatility.  Entire exchanges have been wiped out in the past few years due to security oversights. Still, money is pouring into the cryptocurrency market at a record pace.  

As with any immature market, the price of a cryptocurrency is somewhat open to interpretation with different exchanges often having significantly different pricepoints. This presents an opportunity to increase profit and to mitigate risk.

Numerous exchanges exist for trading cryptocurrencies and each have very different fee schedules, interfaces and offerings.  Regulation of the exchanges is still evolving, and the projects backing them are hosted on a range of technologies.  It is possible, however, to take advantage of the price differences, essentially creating your own derivative by trading simultaneously on 2 or more exchanges when the prices are significantly different.

Have a look at this chart:


Notice that just before 6 am on May 21, the price for bitcoin (BTC) on several exchanges ranged between 2070.86 and 2422.55.  If one had an account on bitstamp with cash and another on localbtc (not realistic, but for illustration) and purchased 1 bitcoin on bitstamp at 2070.86 and simultaneously sold 1 bitcoin via localbtc at 2422.55, after transaction fees, she would have effectively made an instant profit of about $350.00 or over about 17%. The cash can be redeposited in her bank account from localbtc. The bitcoin can be transferred to her virtual wallet or to a more favorable exchange in about 30 minutes.

In general, the above case is quite rare. localbtc is not an actual exchange but a marketplace connecting local bitcoin traders to people who want to pay cash. bitstamp is located in Slovenia and the cost to transfer funds into the exchange can be significant for those who do not have an account in a European bank.

Still, referring again to the chart above, a number of these exchanges have been established in the United States, Asia, Europe, and Central and South America, so there is usually at least a pair of exchanges that are relatively safe and work efficiently with banks in any region.

For purposes of illustration, let's look at Gemini and Coinbse/GDAX, exchanges that are headquartered in the US and work with North American bank transfers.  Deposits and withdrawals are relatively easy and cheap via ACH from major American banks. At the same time, Coinbase was at 2136.65 while Gemini had BTC at 2049.91. Absent fees, simultaneous sale on Coinbase(GDAX) and buy on Gemini results in, effectively, an instant profit of $84 on a single trade. While BTC appreciated significantly on both exchanges throughout the weekend, the pricing inefficiency provided dozens of opportunities to increase yield with profitable offsetting trades with margins ranging from 1.5% to nearly 6%. 


Now for the bad news. Volatility means that these windows are brief.  There are varying spreads on any exchange that must be taken into account. The trade on either side my not close.  This is not innately harmful, but it takes the system out of balance when the market is moving rapidly in one direction.  

Dealing with the spread means monitoring the order book, not the last sale in real time and basing your trade on the current bid where you place your sell order and the current ask where you buy. If you're quick and if you are willing to shave a few cents against the relevant offers, then it's not difficult to place two trades that will close immediately.  I (and many other folks) have written code to accomplish this in real time, but I've also been successful entering trades manually in several exchanges.

Note that this isn't limited to BTC/USD.  Any currency pair that is traded on two or more exchanges is fair game.  Both GDAX and Gemini offer trading in BTCUSD (Bitcoin-Dollar), ETHUSD (Ethereum-Dollar) and ETHBTC (direct exchange of Ethereum for Bitcoin). There is an inherent advantage in ETHBTC arbitrage in that there is no need to deposit cash if you already have cryptocurrency in both exchanges. It's also easier to balance these accounts as crypto can be exchanged directly between the two exchanges and fees are extremely low (.002%).  ETH transfers between exchanges or to an external wallet take a few seconds. BTC generally takes around half an hour. Cash can be used for purchase immediately but cannot be withdrawn (nor can assets purchased with it) for a few days.


With any pair, you choose which currency you want to reflect your profit in.  If you trade BTCUSD and you want to increase dollars, make sure your orders are for the same amount of BTC.  If you want to increase your bitcoin holdings, set your orders for the same dollar amount.

I've built a spreadsheet to help folks who are interested in experimenting with arbitrage opportunity between two exchanges and seeing opportunities develop in real time. You are more than welcome to download it here: 

http://bit.ly/dt_arbtool

This tool is freely offered for your personal use. I don't guarantee support and I accept no responsibility for your results.  The spreadsheet uses public websocket APIs from GDAX and Gemini. You need not have an account on either exchange to receive realtime quotes. Excel is not an appropriate platform for the development of trading bots. This is simply a tool that utilizes realtime orderbook information supplied freely by the exchanges and displays the bid-ask adjusted margins for 3 currency pairs across 2 popular exchanges.

By default, the queries will refresh every minute. In Excel's data tab, you can refresh on demand, up to 6 times per second, by clicking "Refresh All" button in the ribbon menu.


The colored section reflects 6 possible trades, the available gross profit and the sellside ask and buyside bid for each.

Beneath that is a recommendation which is, essentially, the trade with the best current divergence.


All that need be done is to download the spreadsheet and run in excel (the service requests do not work in Google Sheets, unfortunately).  I have tested in Excel 2016.  You will need to enable editing and external connections for the worksheet when it opens.  There are no macros.  The queries can be viewed in the data tab (view all queries) and are URLS that can be cut-pasted into a browser if you'd like to see them that way.  The data returned by each is in the 6 green and white tables on the left-hand side of the sheet.

If you do decide to download the tool, please drop me a comment below and let me know what you think.


Happy trading!

DT











Cryptocoin Arbitrage Excel Tool

Hello, folks. It's been a while since I've written an article, but today I got inspired to dust off my blog.

With the excitement around Bitcoin and related currencies hitting a fever pitch, I thought I'd play around with some investment techniques.  I'll try to get something together that is a bit more detailed, but I wanted to post an excel tool that demonstrates how to detect arbitrage opportunities given the sometimes enormous differences between varias cryptoexchanges.

It can be downloaded here as a .xlsx file: 



This tool is simply an excel spreadsheet that monitors the order books of two popular exchanges (gemini and GDAX).  

From what I can tell, all the exchanges I have looked at have accessible APIs that work in a fairly similar fashion.

This tool does not require an account on the exchanges. It uses only public APIs to analyze the order books and display the instant gain or loss of equal buy/sell orders on different exchanges.


It further selects the "best" or most profitable transaction and highlights this as its recommendation.





Note that it does not take into account fees, which range as high as .3% on each side.

Note also that cryptocurrency exchanges, while inefficient, do move very quickly. Taking action based upon this recommendation may require some quick typing. I have coded this on other platforms to automate and test the orders, but Excel is inappropriate for this (and orders obviously require account information.)

I'm uploading it prior to finishing my article so that friends in the community can evaluate it and make suggestions.  

Obviously, I'm offering this for folks to use as they see fit and I take no responsibility for your trading results.

Quickstart:  The spreadsheet is developed in Excel 2016 and uses automated calls to the web services API's of two exchanges.  The queries are visible in the Excel Query pane. They are simply url datasources that retrieve real-time order book information for BTCUSD, ETHUSD and ETHBTC pairs. The queries should refresh automatically every minute, but you can go to the "Data" tab in excel and click "Refresh All" for faster updates.




Please let me know what you think.

Additional notes:  
  • It doesn't appear to be supported in Google Sheets.  

  • I used excel 2016 to create it and am unsure if web data connections were available without a plugin in previous versions.