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>
list-portfolios.ts
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'],
});

PortfolioListParams

FieldTypeRequiredDescription
pagenumberNoPage number (1-based)
limitnumberNoResults per page
portfolioIdsstring[]NoFilter to specific portfolio IDs

get(portfolioId)

Fetch a single portfolio by its ID.

Signature:

get(portfolioId: string): Promise<Portfolio>
get-portfolio.ts
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()}`);

update(portfolioId, params)

Update a portfolio's properties. Currently supports updating the portfolio name.

Signature:

update(portfolioId: string, params: UpdatePortfolioParams): Promise<Portfolio>
update-portfolio.ts
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()}`);

delete(portfolioId)

Permanently delete a portfolio.

Signature:

delete(portfolioId: string): Promise<void>
delete-portfolio.ts
await chaos.portfolios.delete('portfolio-id');
console.log('Portfolio deleted');
[@portabletext/react] Unknown block type "callout", specify a component for it in the `components.types` prop

byType(portfolioType)

Retrieve all portfolios of a specific type — either 'manual' or 'automatic'.

Signature:

byType(portfolioType: PortfolioType): Promise<Portfolio[]>
by-type.ts
// 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}`);
}
Was this helpful?