Presentation
1/ What is it?
Barbotine's arbitrage bot is a cross-exchange crypto arbitrage system that you can run on any machine running Python 3. It's built on top of an open-source library, CCXT, which manages the connectors to exchanges' APIs and offer a centralized way to connect to more than 50 crypto exchanges.
The demo mode is available for free on Github, it works with paper money, fake money, so you can test and see how it works. There is a full version that works live with real money on real crypto markets. Note that the demo mode might show different results than live mode due to market factors like filling of orders that can't be simulated with fake money.
The bot has an embedded strategy featuring a no-transfer rebalancing system, meaning that it's able to take cross-exchange arbitrage opportunities without transferring the coins from one exchange to another.
The bot can work simultaneousely with an infinite number of exchanges (even if opportunities only involve two exchanges), but the rebalancing system means that it can only handle one pair at a time. You can run multiple instances of the bot, but you'd have to allocate proportionally less money on each individual instance.
The infrastructure of the bot is pretty simple: a file named
2/ More technical details
Barbotine's arbitrage bot uses an asynchronous loop to fetch orderbooks faster on all exchanges simultaneousely (using websockets).
It logs everything in a logs folder, all taken opportunities and information/errors in separate
The bot works with what I call 'sessions'. At the end of each session, a rebalancing happens (See more details about rebalancing). You have to input a session renewal delay, after this delay, it will end the current session and start a new one. This cycle is repeated indefinitely unless you stop the bot. You can also disable automatic session renewal in the config file (
3/ Presentation by video
Installation and usage
1/ Installation guide
1. Clone the Github repository (or download the zip file from Github website)
git clone https://github.com/nelso0/barbotine-arbitrage-bot
2. Go to the folder in your terminal/cmd
cd barbotine-arbitrage-bot
3. Install the required Python modules
pip install -r requirements.txt
4. Set your configuration details in
5. Run with:
python run.py
2/ Usage
You can run it directly with
python run.py <mode> [renew-time-minutes] <balance> <pair> <exchanges list separated by commas (no space!)>
Some details about the parameters:
Examples of usage:
python run.py fake-money 60 1000 SOL/USDT binance,okx,kucoin # run the bot with paper money with renewal enabled happening every 60 min. on Binance, OKX and Kucoin, on the SOL/USDT pair.
python run.py real 3500 ETH/BTC poloniex,bitmex,bingx # run the bot with real money on Bitmex, Poloniex and BingX, on the ETH/BTC pair.
3/ Configuration
In this part, we're gonna breakdown every setting of
* = Mandatory for demo and real modes
* = Mandatory only for real mode
(boolean) You can enable or disable renewal. If you enable it, you need to specify a renewal delay when running the bot (see Usage). Default: False | |
(boolean) Enable if you want to hedge the purchase of cryptos for rebalancing with a short order, to remain in a delta-neutral situation. If enabled, you need to fill in the necessary configuration in the file | |
(string) The command you put in the terminal/cmd to launch python. Usually: python, python3, py... | |
(dict) It's a dictionnary in a dictionnary. The key is exchange's ID (like here), and value is a dictionnary containing necessary API details of that exchange for CCXT. Most of the time, it's this: | |
(string) Telegram API details to send everything to you, don't fill unless you want telegram notifications. If so, this is the apiToken of your telegram bot. | |
(float) Minimum of price difference in % to take the opportunity. Default: 0 | |
(float) Minimum of profit in quote currency (= the second asset of the pair, most of the time USDT). Default: 0 | |
(float) Put a value for the timeout in minutes of the rebalancing orders filling. 0 means deactivated, it means it waits indefinitely for the orders to get filled (default). | |
(boolean) Enable or disable a fake ping delay to better simulate the order filling (see Strategy & FAQ for more details). Default: False | |
(int) Necessary if |
Strategy & FAQ
1/ FAQ
What is the difference between demo/fake-money mode and real mode?
As its title says, the fake-money mode works with a fake balance, and the real mode actually sends orders with your real account balance on the real markets. The fake-money/demo mode simulates everything including trading fees (for both rebalancing orders and opportunity orders) and works with the same prices as the real mode (best bid/best ask).
The bot currently uses market orders to take opportunities (more details in the next section "Strategy"), so the fake-money/demo mode assumes you have a 0ms ping delay and that you get filled at the best bid/ask price fetched when the order is sent. You can enable a setting to simulate a custom ping-delay between the time at which the price is fetched and the time at which the fake order is received and executed by the exchange (see demo_fake_delay in Configuration).
How much profit can I except?
It depends on you, you have to ask this question to yourself and your strategy. The point of this open-source bot is to make it yours. With this bot, I tried to make your life as easier as I can, but I can't do the job for you (and nobody can). When to run it, where to run it, how to run it, with what settings, and why... These are questions you need to answer in order to be profitable. You can see it as a hard task, but in my opinion, it's the beauty of algo-trading. Anyone can create their own strategy and it has to be unique. You are rewarded for creating your own path, isn't it beautiful?
I have errors in the terminal/cmd but the bot doesn't stop, is it a bug?
No, as the bot works with asynchronous websockets to fetch the orderbooks at a very fast pace, some exchanges can close the connection unexpectedly. That's why Barbotine's arbitrage bot has a built-in automatic reconnecting system that handles the reconnection for you. The errors like
2/ Rebalancing & hedging
As said in Technical details, the bot rebalances automatically each X seconds (if you enable
For example, if you run the bot with 1000 as total balance, on the BTC/USDT pair with 4 exchanges, you need to put 1000/4 = 250 USDT in each exchange (spot wallet).
To take opportunities, the bot doesn't transfer the coins. It means it has to buy & sell on both exchanges. This way, we can avoid transfer fees and delay. But in order to do that, we need to have quote-currency AND base-currency. For example, with the BTC/USDT pair, we have to own USDT and BTC in each exchange, to be able to buy BTC on exchange 1, and sell BTC on exchange 2. So, when you start the bot, it will automatically buy base-currency (BTC) on each exchange, with the half of quote-currency (USDT) that you put in it before. At each rebalancing/start of the bot, the balances will look like this:
This is what it will look like with 3 exchanges, 750 total balance, on the BTC/USDT pair. When an opportunity arises, it will calculate all possible opportunities, and the impact on the balances (including all fees). If it's profitable and match
Assuming you want profits in quote-currency (most of the time USDT) and not in base-currency, at the each rebalancing, the bot sells everything back to quote-currency, and buys the appropriate quantity of base-currency to end up having the necessary balances to take opportunities (first schema). This would be perfect for a pair like USDC/USDT, because the ratio always stays equal to 1. But for any other volatile pair like BTC/USDT, if BTC goes down, you'll money when rebalancing happens. That's why Barbotine's arbitrage bot integrates a "delta-neutral" feature. This allows you to configure a futures/perpetual exchange, to automatically place a short order with the appropriate quantity, close it when rebalancing happens, and repeat. Here's a schema describing how the hedging works:
3/ Things to do next
- Rewrite it in other languages such as JS
- Add an UI