Coding a DeFi Arbitrage Bot

Extropy.IO
9 min readOct 29, 2020

Please see our updated article, announcing our arbitrage bot course.

In our previous article, we introduced Decentralized Finance as a whole, casting light upon the basic building blocks of this new ecosystem and the main strategies used to earn passive income, mainly “yield farming” and “arbitrage”.

In this article we are going to guide the readers through a step by step tutorial for building an arbitrage trading bot that works with decentralized exchanges, the bot will also get flashloans in order to borrow funds to use for arbitrage. The full working code can be found on Extropy.io’s gihub repository, Extropy will publish a follow-up article that will examine the code in depth.

What is Arbitrage

Arbitrage is the purchase and sale of an asset in order to profit from a difference in the asset’s price between marketplaces.

An example arbitrage strategy in DeFI would be to buy ETH in exchange for USDT on a decentralized such as Kyber and sell it immediately afterwards on another decentralized exchange such as Uniswap at a higher price, thus making a profit in USDT, i.e. you end up with more USDT in your wallet than you had before the arbitrage. The difficulty in arbitrage lies in finding a price discrepancy (spread) for the same trading pair across two different exchanges. For an overview of the main arbitrage strategies please refer to our previous article.

Why Arbitrage on DeFi

--

--

Extropy.IO

Oxford-based blockchain and zero knowledge consultancy and auditing firm