4

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/

2
  • I am just starting with this API, do you mind telling me who is infura_url? If I don't used it I get an error about the PROVIDER.
    – Ivanovitch
    Apr 14 at 12:26
  • You need to get that API from infura
    – Itsjonie
    Jun 22 at 3:21
2
from decimal import Decimal

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.