Aftermath
  • Aftermath
    • About Aftermath Finance
      • What are we building?
  • Getting Started
    • Creating an account
      • zkLogin
        • Removing a zkLogin account
      • Sui Metamask Snap
      • Native Sui wallets
    • Dynamic Gas
    • Navigating Aftermath
      • Interacting with your Wallet
      • Viewing your Portfolio
      • Changing your Settings
      • Bridge
      • Referrals
  • Trade
    • Smart-Order Router
      • Agg of Aggs
      • Making a trade
      • Exact Out
      • Fees
    • DCA
      • Why should I use DCA
      • How does DCA work
      • Tutorials
        • Creating a DCA order
        • Monitoring DCA progress
        • Advanced Features
      • Fees
      • Contracts
  • Limit Orders
    • Contracts
    • Fees
  • Pools
    • Constant Function Market Maker
      • Tutorials
        • Depositing
        • Withdrawing
        • Creating a Pool
      • Fees
      • Contracts
      • Audit
  • Farms
    • Afterburner Vaults
      • Tutorials
        • Staking into a Farm
        • Claiming Rewards
        • Unstaking
        • Creating a Farm
      • Architecture
        • Vault
        • Stake Position
      • Fees
      • FAQs
  • Liquid Staking
    • afSUI
      • Tutorials
        • Staking
        • Unstaking
      • Architecture
        • Packages & Modules
        • Entry Points
      • Fees
      • FAQs
      • Contracts
      • Audit
  • Perpetuals
    • Aftermath Perpetuals
      • Tutorials
        • Creating an Account
        • Selecting a Market
        • Creating a Market Order
        • Creating a Limit Order
        • Maintaining your Positions
      • Architecture
        • Oracle Prices
        • Margin
        • Account
        • Trading
        • Funding
        • Liquidations
        • Fees
  • GameFi
    • NFT AMM
      • Architecture
        • Fission Vaults
        • AMM Pools
      • Tutorials
        • Buy
        • Sell
        • Deposit
        • Withdraw
      • Sui Overflow
  • Our validator
    • About us
  • Developers
    • Aftermath TS SDK
      • Utils
        • Coin
        • Users Data
        • Authorization
      • Products
        • Prices
        • Router
        • DCA
        • Limit Orders
        • Liquid Staking
        • Pools
        • Farms
    • Aftermath REST API
      • Authorization
  • Egg
    • About Egg
  • Legal
    • Terms of Service
    • Privacy Policy
  • Languages
    • 中文
    • 한국어
  • Links
    • X
    • Telegram
    • Discord
    • Github
    • Medium
    • Aftermath Validator
Powered by GitBook
On this page
  • Initialization
  • Methods
  • Types
  • Example Usage
  1. Developers
  2. Aftermath TS SDK
  3. Products

Prices

The Prices class provides methods for fetching and managing price information for coins on the Sui network, including current prices and 24-hour price changes.

Initialization

const afSdk = new Aftermath("MAINNET");
await afSdk.init(); // initialize provider

const prices = afSdk.Prices();

Methods

getCoinPriceInfo()

Retrieves detailed price information for a single coin. Please note that 24h price change percentage is currently not supported for any coins, and will return 0.

const priceInfo = await prices.getCoinPriceInfo({
	coin: "0x2::sui::SUI", // CoinType
});

console.log(priceInfo);
/*
{
 price: 1.23, // Current price in USD
 priceChange24HoursPercentage: 5.67 // 24h price change percentage
}
*/

getCoinsToPriceInfo()

Fetches price information for multiple coins simultaneously. Please note that 24h price change percentage is currently not supported for any coins, and will return 0.

const priceInfos = await prices.getCoinsToPriceInfo({
	coins: ["0x2::sui::SUI", "0x..."], // Array of CoinTypes
});

console.log(priceInfos);
/*
{
 "0x2::sui::SUI": {
   price: 1.23,
   priceChange24HoursPercentage: 5.67
 },
 "0x...": {
   price: 4.56,
   priceChange24HoursPercentage: -2.34
 }
}
*/

getCoinPrice()

Gets the current price of a single coin in USD.

const price = await prices.getCoinPrice({
	coin: "0x2::sui::SUI",
});

console.log(price); // 1.23

getCoinsToPrice()

Retrieves current prices for multiple coins in USD.

const prices = await prices.getCoinsToPrice({
	coins: ["0x2::sui::SUI", "0x..."],
});

console.log(prices);
/*
{
 "0x2::sui::SUI": 1.23,
 "0x...": 4.56
}
*/

Types

Basic Types

type CoinType = string; // Coin address/identifier
type CoinDecimal = number; // Number of decimal places
type CoinSymbol = string; // Trading symbol for the coin

interface CoinPriceInfo {
	price: number;
	priceChange24HoursPercentage: number;
}

interface CoinWithAmount {
	coin: CoinType;
	amount: number;
}

interface AmountInCoinAndUsd {
	amount: number;
	amountUsd: number;
}

Record Types

type CoinsToPrice = Record<CoinType, number>;
type CoinsToDecimals = Record<CoinType, CoinDecimal>;
type CoinsToPriceInfo = Record<CoinType, CoinPriceInfo>;
type CoinSymbolsToPriceInfo = Record<CoinSymbol, CoinPriceInfo>;
type CoinSymbolToCoinTypes = Record<CoinSymbol, CoinType[]>;

Example Usage

const afSdk = new Aftermath("MAINNET");
await afSdk.init();
const prices = afSdk.Prices();

// Get price info for SUI
const suiPriceInfo = await prices.getCoinPriceInfo({
	coin: "0x2::sui::SUI",
});

// Get prices for multiple coins
const multiPrices = await prices.getCoinsToPrice({
	coins: [
		"0x2::sui::SUI",
		"0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",
	],
});

console.log(`SUI Price: $${suiPriceInfo.price}`);
console.log(`24h Change: ${suiPriceInfo.priceChange24HoursPercentage}%`);
PreviousProductsNextRouter

Last updated 3 months ago