Fetch Price Data

Fetch Price Feed data for pool

You could fetch real-time price data for a given pool

import { v2GetPrice, v2GetPriceWithDecimals } from '@piperx/sdk/src/core'
import { v3GetPrice, v3GetPriceWithDecimals } from '@piperx/sdk/src/core'


price = v2GetPrice(
    token1: string, // token 1 address
    token2: string, // token 2 address
) 

price = v2GetPriceWithDecimals(
    token1: string,
    token2: string,
    decimal1: number,
    decimal2: number
) 

price = v3GetPrice(
    token1: string, // token 1 address
    token2: string, // token 2 address
    fee: number, // 500, 3000, 10000 represent 0.05%, 0.3%, 1% fee
) 

price = v3GetPriceWithDecimals(
    token1: string,
    token2: string,
    decimal1: number,
    decimal2: number,
    fee: number, // 500, 3000, 10000 represent 0.05%, 0.3%, 1% fee
) 

We have four APIs for fetching the price. The v2GetPrice and v3GetPrice will return the real price (1 token1 = X token2) based on the token amount in contract (not considering decimal). If you want the user-facing price, you should use v2GetPriceWithDecimals and v3GetPriceWithDecimals. However, you have to pass the decimals of both tokens.

Last updated