Place Automated Trades with Uniswap

Published: Feb 22, 2025

In this guide we are going to show you the exact steps to placing automated trades with Uniswap in Python.

We’ll start by understanding what the uniswap-python package is and why it makes our life easy, followed by how to initialise a uniswap client. We’ll then go over how to get a quote for any ethereum coin, how to place an automated trade and a bonus at the end on how to ensure you get the lowest fee for your trade.

What is Uniswap-Python?

Uniswap is one of the largest decentralised exchanges for trading coins on the ethereum blockchain.

Uniswap-python in a popular python package which can be used to automate cryptocurrency trading strategies on the ethereum network. It asks as a wrapper to abstract away all the complex logic of making the requests to the ethereum network and does it in a pythonic way.

How to initialize a Uniswap-Python Client?

Firstly we’re going to install the package via

To initialise the uniswap client we need to pass in four parameters:

Our Wallet address we want to trade from: found in your metamask wallet

Our Wallet private key: found in your metamask settings

A provider URL: get one free at infura

Now we have this we can get a quote on any ethereum coin. Here we need to provide three things:

Address of the token we want to purchase (addresses are more accurate than tickers, especially with the sheer amount of memecoins around these days)

Address of the token we want to sell

The number of “decimals” (how many decimal places we shift the whole integer to return to a normal number)

This will print the number in “wei” which is the equivalent of cents instead of dollars. So to convert it back we can divide by 10**18. Or you can simply use the from_wei method found in our web3 guide.

Now that we have our quote, if we’re happy with it we can place a trade by calling:

This will return a transaction hash which contains all the information on the trade we’ve made.