We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hello,
I'm very new to uniswap sdk. I'm trying to figure out with this SDK. Given a contract with the pair, how can I know the current price?
Thanks
The text was updated successfully, but these errors were encountered:
https://uniswap.org/docs/v2/advanced-topics/pricing/ https://uniswap.org/docs/v2/smart-contracts/pair/
Sorry, something went wrong.
Here is my code:
int precision = 10000000; var getAmountsOutFunctionMessage = new GetAmountsOutFunction() { AmountIn = precision, Path = GetPath() // List<>{tokenAddress, ..., usdtAddress} }; var getAmountsOutHandler = web3.Eth.GetContractQueryHandler<GetAmountsOutFunction>(); var amounts = await getAmountsOutHandler .QueryAsync<List<BigInteger>>( routerAddress), getAmountsOutFunctionMessage); var ratio = BigDecimal.Pow(10, usdtDecimals - tokenDecimals); var priceUsd = amounts.Last() / ratio / precision;
Remember to get the decimal difference of the token to USDT, it's important
also the precision should be optimal, any smaller number will cause the query hang if the token price is too small.
excuse for bad design pattern, many of those variables can be reused. I generally just extract some key steps from my code.
No branches or pull requests
Hello,
I'm very new to uniswap sdk. I'm trying to figure out with this SDK. Given a contract with the pair, how can I know the current price?
Thanks
The text was updated successfully, but these errors were encountered: