Tradegen
  • Introduction
  • Tradegen Platform
    • Use Cases
    • Supported Assets
    • Supported Projects
    • Pools
    • NFT Pools
    • Marketplace
  • Tutorial
    • Investing in a Pool
    • Withdrawing From a Pool
    • Creating a Pool
    • Managing a Pool
    • Investing in an NFT Pool
    • Withdrawing From an NFT Pool
    • Creating an NFT Pool
  • Token Info
    • Introduction
    • Allocation
  • SDK
    • Getting Started
    • Entities
      • Price
      • TokenAmount
      • Percent
      • Fraction
      • Token
      • Pool
    • Fetcher
    • Other Exports
  • Technical
    • Implementation
    • Synthetic Trading Bots
    • Mining System
    • Trading Strategies
  • Contracts
    • Asset Management V1
    • Data Feeds
      • Protocol
      • Candlestick Data Feeds
        • 1-Minute Timeframe
        • 5-Minute Timeframe
        • 1-Hour Timeframe
        • 1-Day Timeframe
    • Tradegen Token
    • Algo Trading
      • Core Contracts
      • Indicators
      • Comparators
      • Component IDs
      • Initial Instances and Keepers
    • Asset Management V2
      • Core Contracts
      • Price Calculators
      • Adapters
      • Asset Verifiers
      • Contract Verifiers
    • Virtual Trading Environments
    • Farming System
    • Synthetic Trading Bots
  • Resources
    • Roadmap
    • Equations
    • Protocol Settings
    • Changelog
      • Pre-launch
      • Phase 1
      • Phase 2
    • Links
    • Github
    • Analytics
    • Whitepaper
  • Deprecated
    • Pools
      • Investing in Pools
      • Farming
      • Creating a Pool
      • Managing a Pool
      • System Architecture
    • Strategies
      • Investing in Strategies
      • Claiming Yield
      • Running Backtests
      • Strategy Approval
        • Voting for a Strategy
        • Submitting a Strategy
      • Trading LP Tokens
      • Building a Strategy
      • System Architecture
    • Components
      • Components Marketplace
      • Building Custom Components
      • Submitting Custom Components
Powered by GitBook
On this page
  • Example
  • Properties
  • Methods

Was this helpful?

  1. SDK
  2. Entities

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
PreviousEntitiesNextTokenAmount

Last updated 3 years ago

Was this helpful?