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











3 comments:

חדשות קשת said...

Hi,
Great post.
1. From what I understand if you trade BTC/USD you hold BTC on both exchanges?
If so, isn't it risky if the bitcoin value falls dramatically ?

2. Any thought on statistical arbitrage (https://megatrader.org/en/poleznaja-informacija-en/19-bitcoin-statistical-arbitrage).

Thank you for your time.
Itamar

p.s.
Sent you a comment on youtube too.

DT said...

Thanks for the link. I'll check out the article and respond a bit later.

To your first concern, the native risk of BTC is just what it is. Arbitrage, properly executed provides a guaranteed net profit at the time the offsetting trades are placed. Therefor, if the market is moving down and you're regularly trading profitable arbs, you're reducing your exposure (if your trades are coin-neutral) by taking cash. I tend to try to do more cash-neutral trades because I prefer to accumulate. I don't keep large amounts of cash or crypto on exchanges because they are inherently more risky than a hardware wallet. You don't have control of the keys. I sweep regularly and rebalance the accounts to less than I am willing to risk to a hack or insolvency. That said, most of the exchanges I work with are at least partially regulated and all are well established.

DT said...

So, this is a while ago. Btc trading is risky. You could certainly go flat at any point but, yes, you needed to keep balances in both accounts because you cannot know which side will have the power price. This was one of the biggest challenges: remaining balanced.

DT