简体   繁体   中英

Discrepancy between the getAmountsOut function and the prices on the exchange

I am making an app to get live prices of tokens from the different exchanges. To do this I'm using web3.py to access to the DEX smart contract and call the getAmountsOut function. It should be the most accurate since it comes directly from the dex router, but I often see discrepancies between the numbers I get and the numbers on the actual exchange, and even with dexscreener.

Am I doing something wrong? should I try to include slippage to make it match closer to the exchange? As a note, often the price that I retrieve from the getAmountsOut function is accurate.

Here is the code of the function I am using in python.

routerContract = web3.eth.contract(address=uniswapV2Router, abi=uniswapV2ABI)
oneToken = web3.toWei(1, 'Ether')                                                           
price = routerContract.functions.getAmountsOut(oneToken, [tokenAddress, DAI]).call()        
readablePrice = web3.fromWei(price[1], 'Ether')    

                                    

The connection to the node is not show here, could it be a limitation of the endpoint? Thank you!

There's a 0.3% uniswap fee thats factored in the calculations of getAmountsOut, as such the price with something like dexscreaner will be different

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM