Bot strategies - Triangular Arbitrage
Disclaimer: Although I believe the thinking around this strategy is sound, I was never able to make a profit from it. The reason I'm posting it here, is that I think someone with better technical skills than I might be able to get it to work.
Before getting into the technical details, a quick analogy:
Let's pretend we are car enthusiasts, and every weekend we meet to trade cars (ridiculous analogy I know but stay with me):
- You can trade a Ferrari for a Porsche.
- You can trade a Lamborghini for a Porsche.
- You can trade a Lamborghini for a Ferrari.
Let's assume the value of the cars are all equal. One weekend, something "out of the ordinary" happens. A Porsche owner decides he is willing to trade his 2 Porsches for a Ferrari, because he has always wanted a Ferrari and can’t find a Ferrari owner that is willing to trade at short notice. One of the Ferrari owners decides to accept the 2 Porsches and the trade is done.
Temporarily, the going rates look like this:
- One Ferrari for 2 Porsches.
- One Lamborghini for one Porsche.
- One Lamborghini for one Ferrari.
A clever Ferrari owner spots an opportunity, and performs the following trades.
- Trades his Ferrari for 2 Porsches.
- Trades his 2 Porsches for 2 Lamborghinis.
- Trades his 2 Lamborghinis for 2 Ferraris.
He now has 2 Ferraris from 1, without having incurred any costs, just by making a series of trades in the right order. He was able to do this because there was a pricing discrepancy that he could take advantage of.
This opportunity isn't going to last long though … Porsche owners are very quickly going to start insisting on a "one to one" trade again, and the discrepancy will disappear. This type of scenario happens from time to time on crypto exchanges, but you need to be really quick to take advantage of them.
A real world example
On the Poloniex exchange on the afternoon of the 6th of January 2018 you could make a 0.86% profit (fees included) if you did the trades below in order, very quickly. On that one day alone, there were many more opportunities like this.
- Bitcoin to Ripple
- Ripple to USDT (Tether)
- USDT (Tether) to Litecoin
- Litecoin to Bitcoin
- Congratulations, you now have 1.0086 Bitcoin
If it's that easy, why could I not make a profit?
The reason I could not make this work, was that it would take the bot I developed anything between 2 and 10 seconds to complete each of the trades, the main issue being the quality of my Internet connection, and probably the quality and efficiency of my code. Most times, by the time I was getting to the last trades the discrepancy had already corrected itself, negating the opportunity for profit. I am convinced however that someone with sound technical knowledge, using a fast programming language, running on a fast Internet connection, should be able to make this work to the point where they make more winning than losing trades (and therefore profit).
What would a bot need to do?
- First step is to find a suitable exchange. The main criteria is that the exchange must support the trading of some (or all) crypto currencies into multiple other currencies.
- On Poloniex (https://www.poloniex.com/), I can trade Ethereum to BTC or USDT (Tether), or actually a whole host of other currencies. Because I can trade that specific currency into so many other currencies, there is a good chance that will get pricing discrepancies at some point.
- On Luno (https://www.luno.com/trade/ETHXBT), I can only trade Ethereum to Bitcoin. There will never be pricing discrepancies to exploit if I can only trade to one other currency, so this is not a good exchange for this specific scenario.
- Once an exchange has been selected, the bot must pull all prices for all currencies on the exchange, example https://poloniex.com/public?command=returnTicker.
- For each currency that can be traded into multiple other currencies, the bot now needs to try all the permutations of trades that it can do, to see what the most profitable sequence of trades is, and what the profit would be. I am sure there are more efficient ways to do this but I used a recursive procedure, which is basically a piece of code that calls itself until it reaches a condition where it is told to stop. My bot was told to simulate trades until it got back to Bitcoin again.
- I would start with Bitcoin, and call the procedure for each currency I could trade to…
- …then for each of those currencies call the procedure again for each currency I could trade to from there.
- …then for each of those currencies call the procedure again for each currency I could trade to from there.
- Each iteration would simulate the trades from the previous currency to the current one, tracking the total profit/loss as it goes.
- Eventually I would get back to Bitcoin, at which time I would compare the resulting value to the original starting value. If I now had more Bitcoin, then the path is a profitable one, otherwise not.
- This sounds like a lot of work but all of the permutations only take half a second to calculate so this part doesn't perform too badly.
- Note that when the bot is calculating the most profitable path, it must factor fees in and deduct those for each trade. It must also use the lowest sell price when simulating buy transactions (if you buy at the lowest sell order price then your trade will immediately be filled), and the highest buy price when simulating sell transactions (if you sell at the highest buy order price then your trade will immediately be filled). This is important as you cannot wait for trades to be filled, they need to be filled immediately.
- Once the most profitable sequence has been calculated, and if the end result will be a profit, then the bot must execute the trades in order. This is the part where my code and connection were just not fast enough.
Ideas to improve performance, and therefore the profitability of this strategy:
- When I tried this bot, I ran it on a 15 second schedule. This means that if a "discrepancy" happened that I could exploit, it could take me up to 15 seconds to act on it. Some exchanges provide live trade feeds. If I used this, I would know much sooner that there was an opportunity, and could therefore do the trades much quicker.
- I have considered running the bot from a hosted cloud provider (such as Azure or Amazon), instead of my PC at home. This would theoretically give me better response times on Internet connections, resulting in trades being executed quicker.
- I know the Python http libraries that I use to make the API calls to the exchanges are not the fastest, so I could try to find something faster ... or perhaps even develop the bot in a completely different language.
Ultimately, I weighed the effort of doing all of the above against the other strategies I wanted to try, and decided to "abandon" this strategy for the time being. If anyone takes it further, and gets it to work, that would be absolutely fantastic.
Have I missed anything? Do you have any tips? Do you disagree with any of the above? If so, leave a comment and let's chat.
To listen to the audio version of this article click on the play image.
Brought to you by @tts. If you find it useful please consider upvoting this reply.
Congratulations @cryptoinformer! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :
Click here to view your Board of Honor
If you no longer want to receive notifications, reply to this comment with the word
STOP
Do not miss the last post from @steemitboard:
Congratulations @cryptoinformer! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :
Click here to view your Board of Honor
If you no longer want to receive notifications, reply to this comment with the word
STOP
Do not miss the last post from @steemitboard:
Congratulations @cryptoinformer! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!