unni krishnan
unni krishnan

Reputation: 53

how to calculate the tick from price ? Uniswap v3

enter image description here

This is USDC/ETH pool with 0.05% poolfee. I am planning to get the price range from users (lower price and higher price ) but if the user provide lower price as 0.00025991932 and higher price is 0.00033985099 then how can I calculate the lower tick and uppper tick from the prices provided by the user (lower price and higher price).I mean how to calculate lower tick and uppper tick from the low price and high price?

If anyone knows please help

Upvotes: 0

Views: 676

Answers (1)

Yilmaz
Yilmaz

Reputation: 49671

from the docs

Conceptually, there is a tick at every price p that is an integer power of 1.0001. Identifying ticks by an integer index "i", the price at each is given by

p(i)=1.0001 ^ i

this is price function with "i" parameter. if you apply logarithm, you get

tick=log(p)/log(1.0001)

given those prices:

low=0.00025991932
high=0.00033985099

if you use this online calculator for easy calculation

lower_tick = -82555
higher_tick= -79874

and upper tick is

Upvotes: 1

Related Questions