Price

Responsible for denominating the relative price between two tokens. Denominator and numerator must be unadjusted for decimals. Derived from Fraction entity.

Example

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

Properties

  • baseCurrency (Token type): Numerator

  • quoteCurrency (Token type): Denominator

  • scalar (Fraction type): Used to adjust the raw fraction based on the decimals of the tokens

Methods

raw

Returns the raw price, unadjusted for decimals.

raw(): Fraction

adjusted

Returns the price, adjusted for decimals.

adjusted(): Fraction

invert

invert(): Price

quote

Given an asset amount, returns an equivalent value of the other asset, according to the current price.

quote(currencyAmount: TokenAmount): TokenAmount

multiply

multiply(other: Price): Price

toSignificant

toSignificant(significantDigits: number = 6, format?: object, rounding?: Rounding): string

toFixed

toFixed(decimalPlaces: number = 4, format?: object, rounding?: Rounding): string

Last updated