Uniswap API – How to Get Token Prices

erc-20etherscanpythonuniswap

I am using uniswap python api to get live token prices. I am using all the variation of the built-in functions. However, it does not give me the right value.

HERE IS MY CODE

address = "0x0000000000000000000000000000000000000000"
private_key =  None
uniswap_wrapper = Uniswap(address, private_key,infura_url,version=2)  
dai = "0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359"


print(uniswap_wrapper.get_eth_token_input_price(dai, 5*10**18))
print(uniswap_wrapper.get_token_eth_input_price(dai, 5*10**18))
print(uniswap_wrapper.get_eth_token_output_price(dai, 5*10**18))
print(uniswap_wrapper.get_token_eth_output_price(dai, 5*10**18))

And these are my results respectively,

609629848330146249678
24997277527023953
25306950626771242
2676124437498249933489

I don't want to use coingecko or coinmarketcaps api as they do not list newly released token prices immediately.

I tried etherscan to get token prices but it does not have a built-in function for that. Does anybody has any suggestions on how to fix that or do you know any alternatives?

HERE IS THE FULL API : https://uniswap.org/docs/v2/API/entities/

Best Answer

from decimal import Decimal

web3.fromWei(3841357360894980500000001, 'ether')
Decimal('3841357.360894980500000001')
Related Topic