Price Helpers
Price Helpers
Core Price Functions
// Convert bin ID to price
function getPriceFromBinId(binId: number, binStep: number): number {
const base = 1 + binStep / 10000;
const exponent = binId - 8388608;
return Math.pow(base, exponent);
}
// Convert price to bin ID
function getBinIdFromPrice(price: number, binStep: number): number {
const base = 1 + binStep / 10000;
const binId = Math.log(price) / Math.log(base) + 8388608;
return Math.round(binId);
}
// Get price with high precision
function getPriceFromBinIdPrecise(binId: number, binStep: number): string {
const base = 1 + binStep / 10000;
const exponent = binId - 8388608;
const price = Math.pow(base, exponent);
return price.toPrecision(18);
}Price Formatting
Price Range Calculations
Price Conversions
Bin Navigation
Price Validation
Utility Functions
Last updated