Portfolios

New
Updated

The chaos.portfolios namespace lets you create and manage investment portfolios — both manual (user-defined holdings) and automatic (wallet-tracked). Generate AI reports, refresh analytics, view transactions, and run AI analysis sessions.

portfolios-quickstart.ts
import { Chaos } from '@chaoslabs/ai-sdk';
 
const chaos = new Chaos({ apiKey: process.env.CHAOS_API_KEY! });
 
// Create a manual portfolio with holdings
const portfolio = await chaos.portfolios.createManual({
  name: 'DeFi Blue Chips',
  holdings: [
    { symbol: 'ETH', quantity: 10, purchaseDate: 1704067200 },
    { symbol: 'AAVE', quantity: 50, purchaseDate: 1706745600, purchasePrice: 95 },
  ],
});
 
// List all portfolios
const { data, total } = await chaos.portfolios.list({ page: 1, limit: 20 });
 
// Get an AI-generated report
const report = await chaos.portfolios.report(portfolio.id);
 
// Ask AI about your portfolio
const session = await chaos.portfolios.analyse(portfolio.id, 'How is my portfolio performing?');

Method Reference

MethodHTTPEndpointReturns
createManual(params)POST/v1/portfolios/manualPortfolio
createAutomatic(params)POST/v1/portfolios/automaticPortfolio
list(params?)GET/v1/portfoliosPortfolioListResponse
get(portfolioId)GET/v1/portfolios/{portfolioId}Portfolio
update(portfolioId, params)PUT/v1/portfolios/{portfolioId}Portfolio
delete(portfolioId)DELETE/v1/portfolios/{portfolioId}void
byType(portfolioType)GET/v1/portfolios/type/{portfolioType}Portfolio[]
report(portfolioId)GET/v1/portfolios/{portfolioId}/reportPortfolioReport
refreshReport(portfolioId, force?)POST/v1/portfolios/{portfolioId}/report/refreshRefreshReportResponse
transactions(portfolioId)GET/v1/portfolios/{portfolioId}/transactionsPortfolioTransactions
analyse(portfolioId, query?, clientRequestId?)POST/v1/portfolios/{portfolioId}/analyseSessionData
createSession(params)POST/v1/portfolio/sessionsSessionData
analyze(params)POST/v1/portfolio/analyzePortfolioWorkflowResponse

Core Types

portfolios-types.ts
type PortfolioType = 'manual' | 'automatic';
 
interface PortfolioHolding {
  symbol: string;
  quantity: number;
  purchaseDate: number;          // Unix timestamp
  purchasePrice?: number | null;
  asset_type?: string | null;
}
 
interface CreateManualPortfolioParams {
  name: string;
  holdings: PortfolioHolding[];
}
 
interface CreateAutomaticPortfolioParams {
  name: string;
  wallet_address?: string;
  chain?: string;
}
 
interface UpdatePortfolioParams {
  name?: string;
}
 
interface Portfolio {
  id: string;
  name: string;
  portfolioType: PortfolioType;
  userId: string;
  holdings?: PortfolioHolding[] | null;
  wallets?: unknown[] | null;
  createdAt: number;
  updatedAt: number;
}
 
interface PortfolioListParams {
  page?: number;
  limit?: number;
  portfolioIds?: string[];
}
 
interface PortfolioListResponse {
  data: Portfolio[];
  total: number;
}
 
interface PortfolioReport {
  status: string;
  retry_after?: number | null;
}
 
interface RefreshReportResponse {
  taskId: string;
  message: string;
  retryAfter: number;
}
 
interface PortfolioTransactions {
  transactions: unknown[];
}
 
interface CreatePortfolioSessionParams {
  query: string;
  workflow_id: string;
}
 
interface PortfolioWorkflowParams {
  [key: string]: unknown;
}
 
interface PortfolioWorkflowResponse {
  [key: string]: unknown;
}
 
interface SessionData {
  sessionId: string;
  userId: string;
  createdAt: number;
  updatedAt: number;
  type: string;
  workflowId: string;
  workflowName: string;
  title: string;
  isBookmarked: boolean;
  isPublished: boolean;
  blocks: unknown[];
  agentMessages: unknown[];
}
Was this helpful?