[英]How to get token prices with UNISWAP API
我正在使用 uniswap python api 来获取实时令牌价格。 我正在使用内置函数的所有变体。 但是,它没有给我正确的价值。
这是我的代码
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))
这些分别是我的结果,
609629848330146249678
24997277527023953
25306950626771242
2676124437498249933489
我不想使用 coingecko 或 coinmarketcaps api,因为它们不会立即列出新发布的代币价格。
我尝试使用 etherscan 来获取代币价格,但它没有内置的 function。 有没有人对如何解决这个问题有任何建议,或者你知道任何替代方案吗?
将结果传递到此 function 以将它们从 wei 转换
from decimal import Decimal
web3.fromWei(3841357360894980500000001, 'ether')
Decimal('3841357.360894980500000001')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.