Skip to content

Price API SDK

Fetch USD and native-currency prices for any token on PancakeSwap supported chains, using the PancakeSwap price API.

Installation

npm install @pancakeswap/price-api-sdk

Quick start

import {
  getCurrencyPrice,
  getCurrencyListUsdPrice,
  getTokenPrices,
  getNativeTokenPrices,
} from '@pancakeswap/price-api-sdk'
import { ChainId } from '@pancakeswap/chains'
import { bscTokens } from '@pancakeswap/tokens'
 
// Single token price
const cakePrice = await getCurrencyPrice({
  currency: bscTokens.cake,
  chainId: ChainId.BSC,
})
console.log(`CAKE: ${cakePrice}`)
 
// Multiple tokens at once
const prices = await getCurrencyListUsdPrice({
  currencies: [bscTokens.cake, bscTokens.usdt],
  chainId: ChainId.BSC,
})
// { '0x0E09...': 2.34, '0x55d3...': 1.00 }
 
// Raw addresses (more efficient for large lists)
const tokenPrices = await getTokenPrices({
  chainId: ChainId.BSC,
  addresses: ['0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82'],
})

Functions

getCurrencyPrice

getCurrencyPrice(options: {
  currency: Currency
  chainId: ChainId
}) → Promise<number>

Fetch the USD price for a single currency. Returns 0 if the price is unavailable.

getCurrencyListUsdPrice

getCurrencyListUsdPrice(options: {
  currencies: Currency[]
  chainId: ChainId
}) → Promise<Record<string, number>>

Fetch USD prices for a list of currencies in a single request. Returns a map of checksummed address → price.

getTokenPrices

getTokenPrices(options: {
  chainId: ChainId
  addresses: string[]
}) → Promise<Record<string, number>>

Fetch prices by raw token addresses. More efficient than getCurrencyListUsdPrice when you already have addresses and don't need Token objects.

getNativeTokenPrices

getNativeTokenPrices(options: {
  chainIds: ChainId[]
}) → Promise<Record<number, number>>

Fetch the native currency (ETH, BNB, etc.) USD price for one or more chains. Returns a map of chainId → price.

getPoolType

getPoolType(pool: Pool) → PoolType

Determine the pool type from a pool object.

Return valueDescription
PoolType.V2PancakeSwap V2 pair
PoolType.V3PancakeSwap V3 CL pool
PoolType.STABLEStable pool
PoolType.CLInfinity CL pool
PoolType.BINInfinity Bin pool

Constants

ExportDescription
PoolTypeEnum of pool types
orderPriceApiParsersParse price API responses for order (PCSX) workflows