Listing, Fetching & Managing Portfolios
Updated
Once portfolios are created, use these methods to list, retrieve, update, delete, and filter them.
list(params?)
Retrieve a paginated list of portfolios. Optionally filter by specific portfolio IDs.
Signature:
list(params?: PortfolioListParams): Promise<PortfolioListResponse>Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
import { Chaos } from '@chaoslabs/ai-sdk';
const chaos = new Chaos({ apiKey: process.env.CHAOS_API_KEY! });
// List all portfolios (first page)
const { data: portfolios, total } = await chaos.portfolios.list();
console.log(`${total} portfolios total`);
for (const p of portfolios) {
console.log(`${p.name} (${p.portfolioType}) — created ${new Date(p.createdAt * 1000).toLocaleDateString()}`);
}
// Paginated request
const page2 = await chaos.portfolios.list({ page: 2, limit: 10 });
// Filter by specific IDs
const filtered = await chaos.portfolios.list({
portfolioIds: ['portfolio-id-1', 'portfolio-id-2'],
});Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
PortfolioListParams
| Field | Type | Required | Description |
|---|---|---|---|
page | number | No | Page number (1-based) |
limit | number | No | Results per page |
portfolioIds | string[] | No | Filter to specific portfolio IDs |
get(portfolioId)
Fetch a single portfolio by its ID.
Signature:
get(portfolioId: string): Promise<Portfolio>Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
const portfolio = await chaos.portfolios.get('portfolio-id');
console.log(`Name: ${portfolio.name}`);
console.log(`Type: ${portfolio.portfolioType}`);
console.log(`Holdings: ${portfolio.holdings?.length ?? 0}`);
console.log(`Created: ${new Date(portfolio.createdAt * 1000).toISOString()}`);Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
update(portfolioId, params)
Update a portfolio's properties. Currently supports updating the portfolio name.
Signature:
update(portfolioId: string, params: UpdatePortfolioParams): Promise<Portfolio>Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
const updated = await chaos.portfolios.update('portfolio-id', {
name: 'Renamed DeFi Portfolio',
});
console.log(`Updated: ${updated.name}`);
console.log(`Updated at: ${new Date(updated.updatedAt * 1000).toISOString()}`);Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
delete(portfolioId)
Permanently delete a portfolio.
Signature:
delete(portfolioId: string): Promise<void>Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
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
byType(portfolioType)
Retrieve all portfolios of a specific type — either 'manual' or 'automatic'.
Signature:
byType(portfolioType: PortfolioType): Promise<Portfolio[]>Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
// Get all manual portfolios
const manualPortfolios = await chaos.portfolios.byType('manual');
console.log(`${manualPortfolios.length} manual portfolios`);
// Get all wallet-tracked portfolios
const autoPortfolios = await chaos.portfolios.byType('automatic');
console.log(`${autoPortfolios.length} automatic portfolios`);
for (const p of autoPortfolios) {
console.log(`${p.name} — wallets: ${p.wallets?.length ?? 0}`);
}Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
Was this helpful?