Product Hack: Arbitraging Crypto

How we built an arbitrage trading bot for crypto exchanges and what we learned from it.

Warren Fauvel
Sep 5, 2018 · 4 min read

The problem

Early in 2017 the crypto-currency markets began to fly. As a team, we were already investing in the space, but we wanted to find a way to capitalise on the boom in a more systematic way, as the markets tended to be hugely volatile. So we started exploring trading algorithms, specifically arbitraging.

Arbitrage — the simultaneous buying (bidding) and selling (asking) of currency in different markets in order to take advantage of differing prices for the same asset.

To break that down. I want to sell £1, you will pay $1.15 for it. Someone else is selling £1 for $1.10. If I sell you my £1, but simultaneously buy the other, I make $0.05. As long as I can complete the trade, there is 0 risk for my profit.

The Solution

To analyse the market we integrated data from several crypto exchanges, via their APIs, dumping the data into Google Sheets. We scanned for differences across the exchanges at the same times, then calculated if a trade was profitable, by removing the transaction fees from both exchanges. We then took the minimum volume across the exchanges (this would be the most we could but/sell in a trade) and used this to calculate our absolute profit from the trade. As you can see from the results below, there were LOTS of low profit/low volume trades with a few outliers at low profit/high volume and high profit/low volume. This was enough information for us to continue.

We developed the logic for the algorithm based on a simple model for two exchanges (though we knew we wanted to do multiples in the future), building a system that made concurrent calls to exchanges via a dynamic queuing system. The system looks for differences in the price, figures out the profit margin, calculates the maximum amount that can be bought (based on the balances available) and executes a trade. Excluding API calls, which we can’t control, this can happen 5 times p/second. Over 6 months we completed thousands of profitable trades, learning a lot about how to build a better bot.

What we Learned

  • We could build a superfast/smart system that beat other trading algorithms. This is more a testament to Lee (our CTO) than anyone else. Several things killed our profitability…
  • Failed trades, when exchanges were… busy (we could miss one half of a trade), crashed, or just turned off their APIs without warning. A single missed trade sounds small, but we were moving high volumes of trades and currency, so a missed 0.1% could easily compound into a -0.5% or swing lower as the market changed. This also affected rebalancing…
  • As we have limited capital, we divided it across exchanges and currencies, both for the bid (buy) and ask (sell) side of the markets we are targeting. As trades tended to “flow” from one currency/exchange to another, we’d end up with a 0 balance somewhere and miss lots of profit, requiring us to find ways to rebalance, often as a loss. This was doubled if we were rebalancing due to a failed trade.
  • With Arbitrage you need a lot of capital to make a decent profit. If your average margin is 0.1%, then to make $100 you need to move $100,000. Bearing in mind, you also need to split your money across exchanges and trading pairs, the requirement increases. To make a self sustaining platform we either need to improve our profit margins (this required more exchanges and more capital to fund them), or move more money by not missing any trades (this required more capital p/exchange and a better bot). This links to the next challenge…
  • Lots of people win in a bull market, fewer people win in a bear market. Even though Arbitrage limits the risk of the trade, if you’re trading volatile assets, when they both go down in value, you lose. The more capital we had at risk, the more exposed we were to the volatility of the markets. When they crashed, our portfolio value went down like everyone else’s.
  • Finally, there’s a risk of ‘front running’ as it’s an unregulated market. This is where the exchange chooses to internally arbitrage a currency by swapping between 3+ currencies to make a margin. As they see the data before us, or could in theory provide the data to preferred traders , we could miss out.

Digital innovation in healthcare, AI/ML, blockchain, VR/AR, analytics

Thanks to Lee Driscoll

    Warren Fauvel

    Written by

    nudjed

    nudjed

    Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
    Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
    Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade