Listing & Market Movers

Updated

Browse paginated asset lists with optional filtering, and track what is moving in the market with top gainers, losers, and trending assets.

list(params?)

Returns a paginated list of assets with real-time market data. All parameters are optional -- call with no arguments to get the first page of all asset types.

Parameters:

ParamTypeDescription
pagenumberPage number (1-indexed). Defaults to 1.
limitnumberResults per page. Defaults to server limit.
assetTypeAssetTypeFilter by asset class: 'crypto', 'stock', 'etf', etc.
searchstringKeyword filter applied to name and symbol.

Returns: AssetListResponse

assets-list.ts
import { Chaos } from '@chaoslabs/ai-sdk';
 
const chaos = new Chaos({ apiKey: process.env.CHAOS_API_KEY! });
 
// Get the first page of crypto assets
const { assets, total, page, limit } = await chaos.assets.list({
  assetType: 'crypto',
  limit: 20,
});
 
console.log(`Page ${page} of ${Math.ceil(total / limit)} (${total} total)`);
 
for (const a of assets) {
  const direction = a.change_percent_24h > 0 ? '+' : '';
  console.log(`${a.symbol} — $${a.price} (${direction}${a.change_percent_24h}%)`);
}
assets-list-filter.ts
// Filter by keyword within a specific asset type
const { assets } = await chaos.assets.list({
  assetType: 'stock',
  search: 'tech',
  page: 1,
  limit: 10,
});
 
for (const a of assets) {
  console.log(`${a.name} (${a.symbol}): $${a.price}`);
}

topGainersLosers(assetType?)

Returns the top market movers -- gainers, losers, and trending assets. Pass an AssetType to narrow results to a single asset class, or omit it to get movers across all types.

Parameters:

ParamTypeDescription
assetTypeAssetTypeOptional. Filter movers to a specific asset class.

Returns: TopGainersLosersResponse

assets-movers.ts
import { Chaos } from '@chaoslabs/ai-sdk';
 
const chaos = new Chaos({ apiKey: process.env.CHAOS_API_KEY! });
 
// Crypto market movers
const { top, top_gainers, top_losers, trending } = await chaos.assets.topGainersLosers('crypto');
 
console.log('Top Assets:');
for (const a of top) {
  console.log(`  ${a.symbol}: $${a.price} (mkt cap $${a.market_cap.toLocaleString()})`);
}
 
console.log('\nTop Gainers:');
for (const a of top_gainers) {
  console.log(`  ${a.symbol}: +${a.change_percent_24h.toFixed(2)}%`);
}
 
console.log('\nTop Losers:');
for (const a of top_losers) {
  console.log(`  ${a.symbol}: ${a.change_percent_24h.toFixed(2)}%`);
}
 
if (trending?.length) {
  console.log('\nTrending:');
  for (const a of trending) {
    console.log(`  ${a.symbol}: $${a.price}`);
  }
}
[@portabletext/react] Unknown block type "callout", specify a component for it in the `components.types` prop
Was this helpful?