Cross Exchange Arbitrage: Free Lunch or Not

Photo by Adam Nowakowski on Unsplash

Every now and then we hear people talking about the ideas and practices of making cross exchange arbitrages in the world of cryptocurrency trading. Thanks to their inherent nature of decentralization, cryptocurrencies are traded by people on hundreds of exchanges all over the world 24/7. Democratization of crypto trading has brought the possibility and opportunity for retail traders to operate in a similar manner to professional ones. Running cross exchange arbitrage in the crypto world turns out to be very different from running it in the stock market world: very different in a good sense. In the stock market world only those who have paid enormous amount of premium fees with dedicated straight line optical fiber connections between New York and Chicago can possible scoop some profits into their or their firm’s pockets, and there are a plethora of paperwork, setups, legal registrations, and financial regulations. In the crypto case a college student can become an arbitrager (we did hear that some smart ones were really successful). It isn’t an exaggeration to say that dumb money is floating around everywhere on crypto exchanges. But you have to get it before anybody else does. The idea of performing cross exchange arbitrage is old and simple: when the bids and asks from two different exchanges for exactly the same instrument cross each other, there is an arbitrage opportunity. Is that really as easy as it sounds? We’d say yes and no.

Let us first take a look at the “yes” side. The basic logic needed for implementing a cross exchange arbitrage strategy is straightforward, and largely be divided into three small steps:

  1. For each exchange, subscribe to their market depth data stream for the given instrument.
  2. Whenever a data point is received from an exchange, update the best bids and asks for that exchange.
  3. If the bids and/or asks from the two exchanges cross each other, immediately submit two orders accordingly.

Here is some pseudo code:

class MyEventHandler {
function processEvent {
if exchange is coinbase {
update coinbase's best bids and asks
}
if exchange is gemini {
update gemini's best bids and asks
}
if bestBidPriceCoinbase >= bestAskPriceGemini {
orderQuantity = min(bestBidSizeCoinbase, bestAskSizeGemini)
buy orderQuantity BTC/USD at bestAskPriceGemini at Gemini
sell orderQuantity BTC/USD at bestBidPriceCoinbase at Coinbase
}
// similar if bestBidPriceGemini >= bestAskPriceCoinbase
}
}

main() {
subscribe to coinbase/gemini for BTC/USD market depth data stream with callback function processEvent in MyEventHandler
}

Taking a closer look at the above pseudo code, we can see that the major parts that need to be filled in are streaming data from the exchanges and submitting orders to them. To save you time and energy, we have carefully created a library: https://github.com/crypto-chassis/ccapi_cpp, to fill in those functionalities so that your real code will be nearly the same as the pseudo code (here’s the real code on Github). Don’t you think that coding trading bots using this library feels like writing plain English? We hope it can make your life much easier.

Having looked at the “yes” side of the story, let us turn our attention to the “no” side of it. Running cross exchange arbitrage strategies does need very practical considerations. First, we have to think about how to beat the competitors who are constantly fishing the same opportunities at the same time as you do. Obviously we’d have to stream the exchange’s market data feed as fast as possible, crunch price comparisons between different exchanges as fast as possible, and submit buy/sell orders as fast as possible. Second, we have to think about how to beat the exchanges that charge us a hefty transaction fee. In a high frequency trading setting, even a tiny change in the transaction fee can matter a lot to our profitability. If we are an institutional trader/investor, perhaps we can negotiate it down. Otherwise we’d have to boost our trading volume. Usually the transaction fee is specified as a percentage of the proceeds (e.g. 0.1%) and usually it depends on the account’s trading volume. The higher the trading volume, the lower the transaction fee. Because it is well known that cross exchange arbitrage opportunities aren’t very common, we have to think about how to run the same arbitrage strategies on as many instruments as we feel comfortable in order to boost our trading volume thereby lowering our transaction fee. Last but not least, you have to think about how to beat our infrastructure cost. Careless coding, build, and/or deployments can give us big surprises when at the end of the month Amazon/Microsoft/Google send us the invoices. In the world of high frequency trading, tiny mistakes can quickly grow into a large snowball.

All right. What weapons can you get from us in all these battles? We provide an open-source library (https://github.com/crypto-chassis/ccapi_cpp) to make the coding part orders of magnitude easier on your side: almost like writing plain English. Because it is completely open-sourced, anyone can inspect the code and verify that it was indeed meticulously crafted and optimized for ultra high performance: move semantics, regex optimization, locality of reference, lock contention minimization, etc. Very importantly the library directly connects your server to the exchange’s server and there’s zero middleman in between. All in all, if you meet with any problems in the process of using our library to build your super strategies, feel free to shoot us an email at hello@cryptochassis.com.

Disclaimer: This is an educational post rather than investment/financial advice.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store