Portfolio Management
NewUpdated
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
Create a Portfolio
Manual portfolios let users specify their holdings directly. Each holding needs a symbol, quantity, and purchase date (Unix timestamp).
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`);Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
For wallet-tracked portfolios, provide the wallet address and chain.
const walletPortfolio = await chaos.portfolios.createAutomatic({
name: 'Main Wallet',
wallet_address: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
chain: 'ethereum',
});Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
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.
// 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}`);
}Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
AI Analysis
Ask the AI questions about your portfolio. This starts a conversational session.
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}`);Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
Cleanup
Delete portfolios when no longer needed.
await chaos.portfolios.delete(portfolio.id);
console.log('Portfolio deleted');Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
Was this helpful?