top of page

Uniswap price notification with python

Updated: Jul 29, 2021

In the crypto world, this week Superfarm has launched his ICO(initial coin offering) on Polkastarter. As usual, after their ICO they listed their coin on Uniswap.

In the last couple of months, I observed a very interesting pattern on the newly listed coins on Uniswap, especially for those hyped up. In the first 10-15 minutes after a new coin is listed the price is raising very high then is dropped massively in the next few hours then is going up more than 50% in the next 24 hours. This behavior is most probably because of the boots. Do not even think that you can buy first and then sell after 10 minutes when the price is very high if you do not have an "army" of boots. Also, due to ethereum network congestion, the gas fee is very high during this time (hundreds of dollars).

Image original source here.

Superfarm is in the top most popular newest projects with more than 86K members on Telegram and more than 88K followers on Twitter. So I decided to test the pattern or you can say that I decided to speculate (nothing can be 100% sure in the crypto space). In the first minutes, the price went very high to around 2$ then dropped to around 1$ so I decided to invest 0.98 eth (~1.5K $ at the current price).

The next day I had to watch the price to exit my position on the Superfarm coin if the price was going to raise. Is a real waste of time to check every minute the price so I decided to make a price watcher that will notify me if the price will hit a certain target.



To check the price on Uniswap I have used uniswap-pyhton library.

!pip install uniswap-python

If you are wondering why I have used it the exclamation mark in front of pip is because I have coded in a Jupyter Notebook and I have installed all the necessary python libraries from the notebook cells.

eth = "0x0000000000000000000000000000000000000000"
dai = "0x6B175474E89094C44Da98b954EedeAC495271d0F"
sup = "0xe53EC727dbDEB9E2d5456c3be40cFF031AB40A55"

address = "0x0000000000000000000000000000000000000000"  #  if you're not making transactions
private_key = None  # if you're not going to make transactions

provider = <the url of your provider> # if you use Infura 
 will be 
 like ''
uniswap_wrapper = Uniswap(address, private_key, version=2, provider=provider)  # use Uniswap v2

The first variables contain the ethereum address checksum for the coins that we want to get the price in eth on Uniswap.

To get the ethereum address checksum of a coin you can use Coingecko and get the contract address first:

Then you can use this website to easily get the ethereum address checksum from the contract address.

If you are not very familiar with what is the etherum address checksum you can see it as an identifier, base on this coin identifier Uniswap will be able to give you the price.

The provider (web3 provider) is a website running geth or parity node which talks to Ethereum network. To get a provider you can use Infura. If you will use Infura you have to sign up then just go and create a new project, on the settings tab you could see your provider URL:

To get the Superfarm coin price in eth:

sup_price = uniswap_wrapper.get_token_eth_input_price(sup, 10 ** 18)

print(sup_price / 10**18)
# 0.000901625376604887

10 ** 18 represents the number of Superfarm coins and it has to be an integer value if we choose a small amount the returned value will be 0 (due to the approximation), so we need a big amount. We will get the price in eth for 10 ** 18 Superfarm coins.

If we want to find the price for 1 Superfarm coin in dollars we could use the Dai stable coin (1 Dai ~= 1$). We can request the same amount of Superfarm and Dai coins and then we could divide them.

def get_sup_price_in_dollars():
    sup_price = uniswap_wrapper.get_token_eth_input_price(sup, 10 ** 18)
    dai_price = uniswap_wrapper.get_token_eth_input_price(dai, 10 ** 18)
    return round(sup_price / dai_price, 4)

# 1.357 --> the price in dollars for 1 Superfarm coin

To push the notifications on my desktop I have used the plyer library:

!pip install plyer

Here is the function that will push the Superfarm price and the change since the previous value.:

from plyer import notification

def notify(price: int, new_price: int):
    title = 'Superfarm price whatcher',
    message = f"Total value of SUPER = {new_price}, change: {round(new_price - price, 3)}",
    timeout = 10,
    app_icon = '/home/kederrac/Pictures/uniswap.ICO',

As you can see I also add an app icon, to be able to use the app icon I had to convert my .png picture to .ico format also, I had to install the dbus-python library (no need if you are using windows os).

!pip install  dbus-python

Now let's put it all together:

import time

price = get_sup_price_in_dollars()
notify(price, price)

while True:
    new_price = get_sup_price_in_dollars()
    if abs(price - new_price) > 0.05:
        notify(price, new_price)
    price = new_price

Here I'm calling the get_sup_price_in_dollars() function every 10 seconds to check if the price has changed if the change is greater than 0.05 dollars a notification will be pushed, you may change the minimum value of the change in order to be notified or you can set a minimum price target to be notified.

And the result:

(on ubuntu 20.04)

(on windows 10)


This was really helpful to have real-time price notifications, one more thing that is great about this approach is the speed, you will get minutes faster than if you have to use Coingecko and seconds faster if you use the Uniswap web interface.

Here you can see the pattern that I was talking about in the beginning:

Abot my speculation, I could sell the Superfarm coin the next day after the Uniswap listing with a bit more than 50% profit (sold my Superfarm coins for ~ 1.51 eth) or ~ 800$ at the current eth price. I could say that I was lucky. This is not financial advice! Have a nice day!

930 views0 comments

Recent Posts

See All


bottom of page