How to use my arbitrage bot to make a profit (maybe).

Kyle Leon Jordaan
5 min readSep 1, 2022

--

Photo by Jason Briscoe on Unsplash

As always this is this is not financial advice. Web3ArbitrageBot was only written as an experiment, and may not produce any profit, and you have the potential to lose money due to transaction fees. Crypto currency is a high risk asset please be careful

So if the graph shown above scares you. Know that you are not alone, I am nowhere near comfortable enough to trade for myself. That’s why I built Web3ArbitrageBot, better known as Crypto BOT on Twitter. As always don't be afraid to follow me on Twitter, and you can always ask me anything that you may need help with.

As the name suggests this is an arbitrage trading bot. It is specifically designed to take advantage of Triangular Arbitrage. It does this in the most basic way possible. Query a decentralised exchange for every market available, then check if a profit above a certain percentage is possible. Then trade that opportunity. No clever mathematics, just good old-fashioned brute force. It is most likely leaving profit on the table. But I will get as improvements as I can.

To this point, I have only ever given you a vague ReadMe on how to configure the bot. But I have never given an in-depth tutorial on what needs to be done to use this wonderful piece of software in a real-world situation.

This is that tutorial…

But first some more high-level details. This tutorial will assume that you have a basic understanding of Cryptocurrencies, used the polygon network, and how to use web browser-based wallets like Metamask.

Also, it will be easier if you traded on the polygon network before, because that will make this process a lot easier. You will need some Matic Coins and 1 other token as well.

I won't go through the process of buying Matic as some other resources have done excellent jobs describing the process in more detail than I could. I mean look how simple Kraken has made the purchasing process for you. Therefore I will also assume that you already have some Matic in your Metamask wallet.

It is also assumed that you have git, and python installed on your computer. Once again github.com has provided an excellent resource on how to install its namesake git. For python, you will find that realpython.com has a great tutorial.

Now let's begin…

How to run an arbitrage bot on the Polygon network on windows.

Step 1: Open the CMD from the start menu, and navigate to some location where you want to store the arbitrage bot.

Step 2: Type git clone https://github.com/ljlabs/Web3ArbitrageBot . This will make a copy of Web3ArbitrageBot on your computer.

Step 3: Now we need to configure Web3ArbitrageBot to trade your wallet, on the polygon network. To do this simply open the config.py file on your local computer.

first set line 1 to:

network = "matic"

Then head to meta mask (It is assumed that you already have this installed and configured to the polygon network, details above) and follow the images below.

Select the dot menu in the top left of the screen
Open the account details page
Click the export private key

At this point, you will be asked for your password and then it will give you your private key in the grey text box above.

Now you will be able to set your private_key to something like this. The example below is random text and will be fairly longer than your wallet address, and with no ellipses dots.

private_key = "98d329...234u02"

Now you will be able to get your wallet address by simply clicking your wallet on Metamask.

Click your wallet address to copy it to the clipboard

Now you will be able to set your wallet_address to something like this.

wallet_address = "0xB7569039cd9b6Ee73cE9117adC66e92dc5d33de7"

leave thetrade_volume_limiter untouched as it's an advanced config feature.

trade_volume_limiter = 1

Lastly you will want to, get the token address of the base token you want to trade from and to, as described by the Triangular Arbitrage tutorial. You will most probably want a stable coin like USDC (to minimize your risk), but you can always head to the Uniswap Token Info page and copy the token address like this.

simply use the Uniswap Token Info page (making sure that you are on the polygon network), and copy the token address from the URL on your webbrowser

Finally, you will be able to fill in the base_token field of the config.py.

base_token = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"

At this point, your config.py file should look like this.

network = "matic"
private_key = "98d329...234u02"
wallet_address = "0xB7569039cd9b6Ee73cE9117adC66e92dc5d33de7"
trade_volume_limiter = 1
base_token = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174"

Step 4:

Now using the CMD from Steps 1 and 2, enter this command.

cd Web3ArbitrageBot

Then you will need to install all of the dependencies of Web3ArbitrageBot. To simplify this process I have added a requirements.txt file, therefor the only command you will need to run is.

pip install -r requirements.txt

Step 5: Finally you will be able to run the bot. however, there are 2 programs that will need to be run, the first being chainData.py and the second being arbitrage.py.

You are required to run the chainData.py script first, as this creates the data that arbitrage.py will use to execute trades. To start simply execute:

python chainData.py

and wait until the console starts printing the following in a loop.

sleeping for 60 seconds
reading refresh data from file
refreshing chain data
writing data to file
Time to update graph 0.09

At this point all of the files are ready to be fed into arbitrage.py, so now in a second CMD, you will need to execute the following command.

python arbitrage.py

Hey, presto you are done, your very own arbitrage bot is running now. Your own trading bot is hard at work trying to make a profit for you. if you have any questions please drop the in the comments here, or reach out to me on Twitter, I'm always excited to meet anybody that shares my interests.

But for now, this is the end of this tutorial, I hope it was informative, let me know when Web3ArbitrageBot has made its first trade for you, id love to hear about your experience.

--

--

Kyle Leon Jordaan

I am just a young software engineer in FAANG with a history of various software competitions.