Price
Responsible for denominating the relative price between two tokens. Denominator and numerator must be unadjusted for decimals. Derived from Fraction entity.
This example shows the CELO/USD price, where CELO is the base token, and cUSD is the quote token. The price is constructed from an amount of CELO (the numerator) / an amount of cUSD (the denominator).
import { ChainId, CELO, cUSD, Price } from '@tradegen/sdk'
const Celo = CELO[ChainId.ALFAJORES]
const cUSD = cUSD[ChainId.ALFAJORES]
const price = new Price(Celo, cUSD, '1000000000000000000', '123000000000000000000')
console.log(price.toSignificant(3)) // 123
- baseCurrency (Token type): Numerator
- quoteCurrency (Token type): Denominator
- scalar (Fraction type): Used to adjust the raw fraction based on the decimals of the tokens
Returns the raw price, unadjusted for decimals.
raw(): Fraction
Returns the price, adjusted for decimals.
adjusted(): Fraction
invert(): Price
Given an asset amount, returns an equivalent value of the other asset, according to the current price.
quote(currencyAmount: TokenAmount): TokenAmount
multiply(other: Price): Price
toSignificant(significantDigits: number = 6, format?: object, rounding?: Rounding): string
toFixed(decimalPlaces: number = 4, format?: object, rounding?: Rounding): string
Last modified 2yr ago