Bin Id From Price
Conversion Functions
function getIdFromPrice(price: number, binStep: number): number {
/**
* Convert a price to the underlying binId.
*
* @param price - Price of the bin.
* @param binStep - BinStep of the pair.
* @return BinId of the underlying bin.
*/
return Math.trunc(Math.log(price) / Math.log(1 + binStep / 10_000)) + 8388608;
}import math
def getIdFromPrice(price: float, binStep: int) -> int:
"""
Convert a price to the underlying binId.
:param price: Price of the bin.
:param binStep: BinStep of the pair.
:return: Id of the underlying bin.
"""
return (
math.trunc(math.log(price) / math.log(1 + binStep / 10_000)) + 8388608
)Example
getIdFromPrice(1.075, 5)
>>> 8388752Last updated