/** * Prices — Token prices, history, search, and discovery. * * Run: npx tsx examples/05-prices.ts */ import { Spectrum } from '@spectrumnodes/sdk'; const spectrum = new Spectrum({ api: process.env.SPECTRUM_API! }); async function main() { // --- getPrice --- const eth = await spectrum.prices.getPrice('ETH'); console.log( `${eth.name} (${eth.symbol}): $${eth.priceUsd}${eth.priceEur !== null ? ` / €${eth.priceEur}` : ''} as of ${eth.lastUpdated}`, ); // --- getPriceHistory --- const history = await spectrum.prices.getPriceHistory('BTC', { days: 7, currency: 'usd' }); console.log(`\nBTC 7-day price history (${history.prices.length} points):`); for (const p of history.prices.slice(0, 3)) { console.log(` ${p.date}: $${p.price.toFixed(2)}`); } // --- getTopPrices --- const top = await spectrum.prices.getTopPrices({ limit: 5 }); console.log('\nTop 5 tokens by market cap:'); for (const t of top.results) { console.log(` ${t.symbol}: $${t.price}`); } // --- searchTokens --- const results = await spectrum.prices.searchTokens('uniswap', { limit: 3 }); console.log('\nSearch "uniswap":'); for (const t of results.results) { console.log(` ${t.name} (${t.symbol})`); } // --- getTokenAddresses --- const addrs = await spectrum.prices.getTokenAddresses('USDC'); console.log('\nUSDC contract addresses:'); for (const entry of addrs.addresses) { console.log(` ${entry.chainName} (${entry.chain}): ${entry.address}`); } } main().catch(console.error);