In this project, we create an arbitrage bot.
For the first version, we download OHLCV minutes data for BTC/USDT, ETH/USDT and ETH/BTC on Binance.
Then, we go through the data and only make a transaction when we can buy BTC/USDT, then buy ETH/USDT, and then sell ETH/UDST and be profitable with fees or when we can buy ETH/USDT, sell ETH/BTC and sell BTC/USDT and be profitable with fees.
We are able to go from $1,000,000 to $3,208,288 with the data going from Feb. 9, 2018 to Dec. 7 2022.
This algorythm is good but arbitrage does not work like this in real life. We have to take into account the spread between the bid and ask side.
For the second version, we downlaod the orderbook data using Binance websockts. Then we make a transaction only when it is profitable using the spread between bid and ask. Since we only have 1 price for ask and bid, we also make the approximation that there is an unlimited quantity.
When we put a fee, there is no transaction that makes profitable trad over all the data acquired.
If we lower the fee to 0, we have the following result for data acquired during 3 minutes:
This results are still not representative of reality for 2 main reasons : 1) 0% fee might not be realistic and 2) we havn't look for the quantity for each bid and ask.
Now, if we take into account the bid and ask quantity, we have much less performance. We only generate 0.076% over the period (instead of 90% for the V2.1):
On the third version, we also get the book data with a depth of 20 for both bids and asks. Every time we make a trade, we update our data to reflect the change in supply.
With 0 fees we have the following graph :
And with 0.1% fee per trades, we have the following one :
Merge the data collect and the trade part.
We don't save the data anymore, we just keep the last current known state of the order book.
Deploy live with real trade (i.e. v4 with real trade capacity).
Fully working but we can't get any trade with 0.075% fees.
Taker order added. For example, keep track of ETHBTC and ETHUSDT and put a limit order on BTCUSDT ready to be arbitraged.
Running properly but not making money.
We optimize using only 2 WebSockets. For example, we collect only the current bid/ask for ETHBTC and ETHUSDT and place a limit order for BTCUSDT.
We also need to avoid running multiple instances of the TraderBot class in parallel since it doesn't work well.