Portfolio Management

New
Updated

Build portfolio tracking into your application — let users create portfolios from manual holdings or wallet addresses, generate AI reports, and ask questions about their positions.

In this guide you'll learn how to:

  • Create manual and automatic portfolios
  • List and filter portfolios
  • Generate and refresh AI reports
  • Run AI analysis on a portfolio
[@portabletext/react] Unknown block type "callout", specify a component for it in the `components.types` prop

Create a Portfolio

Manual portfolios let users specify their holdings directly. Each holding needs a symbol, quantity, and purchase date (Unix timestamp).

create-portfolio.ts
import { Chaos } from '@chaoslabs/ai-sdk';
 
const chaos = new Chaos({ apiKey: process.env.CHAOS_API_KEY! });
 
const portfolio = await chaos.portfolios.createManual({
  name: 'DeFi Holdings',
  holdings: [
    { symbol: 'ETH', quantity: 5, purchaseDate: 1704067200 },
    { symbol: 'AAVE', quantity: 50, purchaseDate: 1706745600, purchasePrice: 95 },
    { symbol: 'UNI', quantity: 200, purchaseDate: 1709251200 },
  ],
});
 
console.log(`Portfolio created: ${portfolio.id}`);
console.log(`Holdings: ${portfolio.holdings?.length ?? 0} assets`);

For wallet-tracked portfolios, provide the wallet address and chain.

create-auto-portfolio.ts
const walletPortfolio = await chaos.portfolios.createAutomatic({
  name: 'Main Wallet',
  wallet_address: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
  chain: 'ethereum',
});

Generate a Report

Portfolio reports are AI-generated analytics. The first call may return status: 'pending' — poll until it's ready, or force a refresh.

portfolio-report.ts
// Check if a report exists
const report = await chaos.portfolios.report(portfolio.id);
 
if (report.status === 'ready') {
  console.log('Report is ready!');
} else {
  // Force a new report generation
  const refresh = await chaos.portfolios.refreshReport(portfolio.id, true);
  console.log(`Generating report... retry in ${refresh.retryAfter}s`);
 
  // Poll until ready
  await new Promise(r => setTimeout(r, refresh.retryAfter * 1000));
  const updated = await chaos.portfolios.report(portfolio.id);
  console.log(`Report status: ${updated.status}`);
}

AI Analysis

Ask the AI questions about your portfolio. This starts a conversational session.

portfolio-analysis.ts
const session = await chaos.portfolios.analyse(
  portfolio.id,
  'What are my biggest risk exposures and how should I rebalance?'
);
 
console.log(`Session: ${session.sessionId}`);
console.log(`Title: ${session.title}`);

Cleanup

Delete portfolios when no longer needed.

cleanup.ts
await chaos.portfolios.delete(portfolio.id);
console.log('Portfolio deleted');
Was this helpful?