In this example we will look at AVAX price and we will take the WAVAX / USDT pool on pangolin at this address : 0x9ee0a4e21bd333a6bb2ab298194320b8daa26516
In order to make requests to a contract we need its ABI, it's like a definition of its functions and variables in JSON format.
Now we can read it from our python script (we also need to import the json module)
We need to transform our address to a Checksum valid address or web3.py won't accept it.
Our program is now :
Now we need to make a call to retrieve reserves of each token on this pool
(It exists two types of call to a contract one which just read on the blockchain the informations : we call it with .call() and another one which write and really interact with the blockchain : we call it with .transact() )
The function returns a list of 3 : reserveToken0 , reserveToken1 and timestamp of last update.
Our problem is we don't know which of token0 or token1 is WAVAX or USDT we could check manually but we want our bot to work even with other pool in unknown orders so we need to check which one is which.