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