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}%`);

Last updated