Crypto Arbitrage Guide – What It Is and How to Find It

10 min read

Get 10-day Free Algo Trading Course

Loading

Last Updated on May 14, 2021

Table of contents:

  1. What is crypto arbitrage?
  2. Why does crypto arbitrage occur?
  3. What are the Pros and Cons of crypto arbitrage?
  4. What types of arbitrage exist?
  5. How to take advantage of arbitrage algorithmically?
  6. How to find a crypto arbitrage?
  7. What are the dangers of crypto arbitrage?
  8. Full code

What is crypto arbitrage?

The crypto arbitrage is a strategy to take advantage of an asset trading at different prices at different exchanges.

To put it simply, if we buy a crypto asset for a lower price on one exchange and sell it for a higher price on another exchange, we have used the crypto arbitrage method.

This article focuses on finding cryptocurrency mispricing across several exchanges in order to do a crypto arbitrage. We’ll cover how to calculate the opportunity for a crypto arbitrage and make a profit off of it.

Why does crypto arbitrage occur?

According to most financial textbooks, it is believed that markets are efficient and thus that an arbitrage opportunity simply can’t occur. (Un)Fortunately, the reality is far from theory and traders have found a way to exploit it.

There are many reasons behind the occurrence of a crypto arbitrage and I’ve extracted the most notable ones:

Liquidity variance across several exchanges

Most of the exchanges have their own order books that tend to be different with varying liquidity for a particular asset. For those new to trading, an order book is an automated list of current sell and buy positions for a specified asset.

For example, if we are buying Bitcoin, it might be easier to convert it into cash on a particular exchange without causing a loss. This can easily have something to do with the order book of an exchange.

If one exchange has a wide order book and the other a more filled one, it would be wise for us to buy our asset on the latter, as the former would end up in us paying a higher price.

But why does this happen if both order books show the same price for our asset?

Well, one exchange (with the wide order book) can be made up of small orders of BTC at the very top of its book price.

After we buy these orders, we’re automatically moving into the lower levels of the order book to make the rest of our order, and thus paying a higher price.

Different types of exchanges

Not all exchanges are the same. Some of them are most suitable for retail investors while others are built with a preference for institutional ones.

If we take a look at the varying behaviors and preferences of these two types of traders, a crypto arbitrage opportunity occurs.

For example, the institutional traders tend to have gaps between their large limit market orders while the retail traders don’t.

This gap allows us to buy a particular asset on the retail trader exchange and then commit to a sell position on the other one. With the power of algorithmic trading, most arbitrages can offer an instantaneous profit.

Withdrawal and deposit times vary across exchanges

As exchanges don’t have the same deposit and withdrawal times the opportunities for the crypto arbitrage grow. If we could move our fiat and crypto assets instantaneously, the market differences between several exchanges would flatten out.

This means that the exchanges with a faster transfer time catch up with the market sooner while the other ones slowly crawl up to the updated market sentiment levels.

Moreover, the cost of transferring our fiat/crypto holdings also varies and thus creates even more arbitrage opportunities.

The supply and demand vary across countries

As countries can have different supply and demand levels, we can exploit the crypto arbitrage opportunities.

If Japan has a lukewarm sentiment for Ethereum while the US is going bullish, we can buy the ETH in Japan and sell it to the US.

Foreign currency rates

For example, if we’re trading Lithium, the varying currency exchange rates can create arbitrage opportunities.

Imagine a scenario where the USD gains against the JPY, while the asset price for Lithium remains the same on Japanese and US exchanges.

This creates an arbitrage opportunity where we convert USD to JPY, buy Lithium on a Japanese Exchange and then sell the Lithium on a US exchange.

Some of the other notable reasons are the following:

  • Tight capital controls outside of the US and EU
  • Lack of traders (i.e. market makers)
  • Regulations across exchanges
  • Spreads
  • Costs

What are the Pros and Cons of crypto arbitrage?

The Pros:

  • Low risk – As we’re buying and selling the asset simultaneously, there is no risk involved as there is in the long-term investments.
  • Flourishes in volatile markets – Arbitrage trading is a good way to trade the volatile markets without taking too much risk.
  • Not reliant on bull or bear markets – You can money regardless of market direction. That said, there will be more arbitrage opportunities during massive bull markets. This is because traders are more focused on riding the bull run than arbitraging.
Source: The Economist

The Cons:

  • Transaction fees – Exchanges mostly make a profit from the transaction fees they impose on traders. While someone as a swing trader doesn’t bat an eye on the transaction fees, it can hurt the arbitrage trader and bring his profit to minimum amounts.
  • Exchanges and cryptocurrencies are unpredictable – Most of us can remember a moment when a crypto exchange freezes or crasher on us in times of high volume. Not to speak of some transaction times and cost issues. An exchange might shut down and take all your capital with them too.
  • Technology – If we want to excel at crypto arbitrage, we need to use the latest technology that allows us to make the trades quickly enough in order to make a profit.
  • Minimum mispricing – Considering the costs, transaction fees and the stability of the market, a crypto mispricing has to be high enough such that you are profitable after costs.
  • Regulations – Regulations like KYC (Know Your Client) and AML (Anti-Money Laundering), can impact the cross-border arbitrage.
  • Experience – New traders can jump too quickly on an asset without considering all the ways the arbitrage could go wrong. Thus, having experience in trading and on the fluctuations of the market is key.

What types of arbitrage exist?

There are many ways to commit to a crypto arbitrage and I’ll cover the most used ones.

Spatial arbitrage

This arbitrage is the most common one. It allows us to buy a crypto asset on one exchange and then transfer it to the other exchange while selling it for a higher price.

Issues like costs, transfer times and spreads, make this type of arbitrage not as valuable. Basically, by the time we transfer a crypto to another exchange, chances are that the price has already changed.

The good side of this arbitrage tactic is that it’s quite easy to do.

2 Methods

  1. Long/short on exchange 1, transfer crypto/fiat to exchange 2, then short/long
  2. Long and short on 2 exchanges, then transfer the long to the other exchange, and cover the shorts.

Spatial arbitrage without transferring

This method is used in order to eliminate the transfer time and cost. It is also preferred by most crypto day trading arbitrageurs.

Method 1

In this case, we long ETH and short ETH on another, we then wait for the price of ETH to converge to the same price.

We then close both trades.

The downside of this method is that convergence of the mispricing needs to happen.

Method 2

This tactic involves having a balance on two different exchanges, let’s say Binance and BitMex.

After looking into the spreads of the ETH-USD asset, we decide to buy the asset on Binance and sell it on BitMex. This would be done by moving our USD to Binance and the ETH to BitMex.

Then we would wait for the price to difference to reach X% more on BitMex. When it happens we will commit to a buy ETH order with the USD from Binance, and simultaneously commit to a sell ETH order for USD on BitMex.

Let us now add some numbers to this example so it can be clearer. Let’s say we bought 1 ETH for $6,06 on Binance we would have spent $606.

If we then sold our 1 ETH at the same time on BitMex at a rate of $6,20 we would have sold it for $620.

This means that we simultaneously bought 1 ETH and sold 1 ETH. We didn’t lose or gain one. The profit we made from this is $14, not including the trading fees.

Triangular arbitrage

This tactic utilizes a single or more exchanges while exploiting the differences between the trading pairs. As many exchanges have a great variety of markets with different currency options, we can utilize many opportunities for a triangular arbitrage.

For example, we can trade BTC for ETH, ETH to LTC and LTC back to BTC. If the differences were substantial, we would have made a profit.

To make this example clearer let us go over the method step by step.

Firstly, we’ll begin at one asset, here being BTC. This asset will be the starting and the finishing point of our arbitrage loop.

Secondly, we will trade this first asset (BTC) for a second one, here being ETH. Make sure that this second asset is connected to the starting and the following one.

Thirdly, we will trade our second asset (ETH) for a third one, here being LTC. Make sure that this third asset is connected to the second and first one.

And at the end, all we need to is to convert this third asset (LTC) back to the starting one (BTC).

Triangular Arbitrage Example

As shown in the picture above, we will begin with the value of 1000 BTC. In order to calculate the opportunity and its value, we will simply go around the triangle by calculating the bid and ask prices for each cryptocurrency.

In order to calculate the ratio we are dividing the ETH by LTC. As you can see I’ve set the multiply and divide symbols that you use while going around the triangle.

Let’s calculate it together:

1000 x 0.032 / 6.97 x 223.66 = 1026.85 BTC

If we compare our newly computed value with the starting one, we can calculate the size of our opportunity.

How to take advantage of arbitrage algorithmically?

As arbitrage opportunities last for a few seconds up to a few minutes, it is too time-consuming for a trader to calculate all the possibilities. This is where the algorithmic traders jump in with their cool algos that do the job quickly.

Some traders prefer making the final decision when it comes to their arbitrage and thus they make an alert program that scans across multiple exchanges and notifies the trader with arbitrage possibilities.

There are even third-party software that specializes in notifying subscribed traders with arbitrage opportunities. But beware! There are many scams out there when it comes to this software, so I would advise extensive research before picking one.

As this article is focusing more on how to find mispricing I won’t dabble further in how these algorithms are coded.

I’d advise the reader to check out our Binance and BitMex API guides so you get an idea of how to build an arbitrage.

How to find a crypto arbitrage?

When it comes to finding crypto arbitrage opportunities, it can be done by two main methods. Let’s cover both of them step-by-step.

Method 1

The first method involves using an exchange API from two different exchanges to compare the prices of the asset. This method is accurate but it suffers from not being scalable.

Allow me to show you how to do it. I’ll be using BitMex and Coinbase for this. Have in mind that we’re only going to look for the mispricing, we won’t fire any trades.

If you want to fire a trade, check out our Coinbase and BitMex API guides.

Let us begin by importing the relevant libraries that we need:

import bitmex
import requests
import json
import datetime
from coinbase.wallet.client import Client
from time import sleep

The next step is to validate our API Keys and API Secrets:

bitmex_api_key = 'EeE092m3lwJism5mAFc4plfX' 
bitmex_api_secret = 'kgRLOsB7QOfauIyyNj5VOvPQ8ueLCuWWxwXTAI4ABcqqEMqk'

coinbase_API_key = 'cTgYvXpaksr5fFgr'
coinbase_API_secret = 'Css2cMN9kTjPNh2XvuHLM9HrdVcX3ty5'

Now, let’s set up the clients:

client = bitmex.bitmex(api_key= bitmex_api_key, api_secret=bitmex_api_secret)

clientb = Client(coinbase_API_key, coinbase_API_secret)

The next step is to create a loop that will check for the percent change between the two cryptocurrencies (BTC) prices. If the percent hits the 1.5% mark, we will want the program to notify us.

Have in mind that for BitMex, we need to process the position endpoint result in order to get what we need. When it comes to Coinbase, we’ll need to convert the obtained JSON string into a float value in order to calculate the percentage.

Depending on your API package and limit you’ll freely tweak the sleep times between API calls.

while True:
    positions = client.Position.Position_get(filter=json.dumps({"symbol": 'XBTUSD'})).result()[0][0]
    bitmex_btc = {}
    
    bitmex_btc["markPrice"] = positions["markPrice"]
    print('BitMex: ',bitmex_btc['markPrice'])
    
    coinbase_btc = clientb.get_spot_price(currency_pair= 'BTC-USD')
    print('Coinbase: ',coinbase_btc['amount'])
    
    percent = float(((float(coinbase_btc['amount']) - bitmex_btc['markPrice']) * 100) / bitmex_btc['markPrice']) 
    
    sleep (1)
    
    if percent < 1.5:
        print ('No arbitrage possibility')
        continue
    
    else:
        if percent == 1.5:
            print ('ARBITRAGE TIME')
            break
    sleep(1)

Method 2

The second method involves using data pulling APIs and websites that can scan across multiple exchanges, i.e. CoinGecko or CoinMarketCap. This method is less accurate than the previous one but is vastly scalable.

For this example, we will use CoinGecko, which is a data provider and a crypto tracking website. If you want to learn more about CoinGecko and check out their API, visit the following link:

Let’s begin by importing the relevant libraries we need:

import json
from time import sleep
from pycoingecko import CoinGeckoAPI
cg = CoinGeckoAPI()

Now, we’ll call the CoinGecko API function that pulls the Bitcoin data for all exchanges it has:

coin_tickers = cg.get_coin_ticker_by_id(id='bitcoin')
coin_tickers

The next, thing we want to zoom onto is the ‘tickers” part as it holds the last price data value. I will also make a new variable “btc” upon which we will make our data pulling and calculations.

btc = coin_tickers['tickers']
btc

The next thing is to create a list for all the processed last price values. As I want to see currencies that deviate 1.5% from the specified currency, we’ll make an average starting price to compare the rest to.

Notice how the last part of the if statement weeds out the outliers. Without it, one BTC instance was priced at more than $500k. This is good to keep in mind and implement as data can have bugs or mistakes in it.

all_prices = []
for i in btc:
    if i['target'] == 'USDT' or i['target'] == 'USD' and i['last']<500000:
        all_prices.append(i['last'])
        
starting_price = sum(all_prices)/len(all_prices)
processed = []

The next thing is to create a loop that will pull the data, calculate the percentage, and append it to the processed list. After that, we want the program to show us only the values that match our criteria.

If the data doesn’t match our criteria we’ll run the loop after a specified time frame.

while True:
    for exchange in btc:
        if exchange['target'] == 'USDT' or exchange['target'] == 'USD' and exchange['last'] < 500000:
            percent = float(((starting_price - exchange['last']) * 100) / exchange['last'])
            if percent >= 1.5 and exchange['last'] >= 100:
                processed.append(str(exchange['market']['name']) +':'+ str(exchange['last']))
        if len(processed) == 0:
            sleep(30)
            continue
        else:
            break
    
processed

What are the dangers of crypto arbitrage?

Crypto arbitrage methods carry some danger with them and I’ll share the most notable ones with you:

High fees

Many traders are aware of the withdrawal fees that exchanges charge but some exchanges even charge deposit fees. And these fees can easily pile up and be get up to $20 per exchange.

Time

Most crypto arbitrage opportunities aren’t long-lived because the markets fluctuate and adjust. If the market changes while you’re in the process of a crypto arbitrage, most often, you’re in for a loss.

Volume

If you’re not careful enough, you might end up trying to sell delisted coins with no volume. This will get you stuck and you’re going to lose most of you starting money.

Moreover, a coin may have volume but the volume can be the one that you don’t prefer for your buying and selling prices. Also, take in mind the exchange depth as they might be hyped up.

Transaction issues

Exchanges can get bugged and that’s where the fun on exchange overload, withdrawal issues, crashing, wallet issues and etc. come into play. This can ruin your arbitrage process which depends on speed and efficiency.

Full code

GitHub Link

Igor Radovanovic