Arbitrage in Bitfinex

MH Tsai
codeburst
Published in
3 min readJan 16, 2018

--

Our goal, simply, is to take advantage of different exchange rate between each coin in Bitfinex.

https://static.pexels.com/photos/730567/pexels-photo-730567.jpeg

Arbitrage, huh?

Currency arbitrage is the practice of taking advantage of price differences between markets. These price differences emerge because certain exchanges are more liquid than others.

For example, there is always a different change rate between each cryptocurrency change to Bitcoin or USD (see figure 1). What you need to do, is calculating if it is profitable when you buy LTC with USD, and sell LTC to BTC, and buy ETH with BTC and sell ETH back to USD and if it’s profitable, good for you.

figure 1

So what is the strategy here?

Using your luminous eyes to read every single data (which either red or green) into your brain, and let your gifted brain work as fast as it could be, and try to figure out what might be profitable.

Then use the mouse you just bought or the trackpad on your laptop, click click click click, and literate it all at once.

Kidding, let the code do the work!

I wrote it in nodejs, including both part of finding the most profitable trading and automated trading if a single arbitrage’s profit margin is higher than a threshold.

And this is how it looks like.

The profit margin of different combination.

So what does the picture above actually mean? Take the row start with “0.6895” as an example, it means that if you buy NEO with USD and sell it back to BTC and buy ETP with BTC and sell it back to USD, you have a 0.6895% profit, say if you start with $50 you’ll get $50.34475 ideally(without the fees in Bitfinex, buy and sell all at correct pirce), after doing four steps above.

It should be noted that this code is only a proof of concept, it’s still far from make sustainable profit from it, things like the fee is too high for most of the users and the trading speed is too slow to get the correct price, will lead to an unexpected result.

There will be a breaking change in bitfinex-api-node v2.0, if the code failed to work correctly, that might be a reason. Any pull request is welcome!

Cheers!

Clap if you like it and follow me for more interested article!

Thanks for reading! :)

You can also find me on LinkedIn, Instagram, Facebook, Github.

--

--

https://mhtsai.me | Software engineer by day, Web3 enthusiast by night. Dreams of being a productivity guru.