Creating Portfolios
Updated
The SDK supports two portfolio types: manual portfolios where you specify holdings directly, and automatic portfolios that track a wallet address on-chain. Both return a Portfolio object on creation.
createManual(params)
Create a portfolio with manually specified holdings. Each holding requires a symbol, quantity, and purchaseDate (Unix timestamp in seconds). Optionally include purchasePrice and asset_type.
Signature:
createManual(params: CreateManualPortfolioParams): Promise<Portfolio>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! });
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 },
{ symbol: 'UNI', quantity: 200, purchaseDate: 1709251200, asset_type: 'crypto' },
{ symbol: 'SOL', quantity: 25, purchaseDate: 1711929600, purchasePrice: 145.50 },
],
});
console.log(`Created: ${portfolio.id}`);
console.log(`Name: ${portfolio.name}`);
console.log(`Type: ${portfolio.portfolioType}`); // 'manual'
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
createAutomatic(params)
Create a wallet-tracked portfolio that automatically discovers and tracks holdings. Provide the wallet_address and optionally a chain to scope the tracking.
Signature:
createAutomatic(params: CreateAutomaticPortfolioParams): Promise<Portfolio>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! });
const portfolio = await chaos.portfolios.createAutomatic({
name: 'My Ethereum Wallet',
wallet_address: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
chain: 'ethereum',
});
console.log(`Created: ${portfolio.id}`);
console.log(`Type: ${portfolio.portfolioType}`); // 'automatic'
console.log(`Wallets: ${portfolio.wallets?.length ?? 0}`);Copy code
Open in Cursor
Open in VS Code
Open in v0
Open in Claude
Open in ChatGPT
Manual vs Automatic
| Feature | Manual | Automatic |
|---|---|---|
| Holdings source | User-provided array | Discovered from wallet on-chain |
| Requires wallet | No | Yes (wallet_address) |
| Holdings update | User must update manually | Synced automatically |
| Chain scoping | N/A | Optional chain parameter |
| Use case | Model portfolios, watchlists, hypothetical allocations | Track real wallet positions |
Parameter Types
CreateManualPortfolioParams
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Display name for the portfolio |
holdings | PortfolioHolding[] | Yes | Array of holdings |
CreateAutomaticPortfolioParams
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Display name for the portfolio |
wallet_address | string | No | Wallet address to track |
chain | string | No | Chain to scope tracking (e.g., 'ethereum', 'polygon') |
PortfolioHolding
| Field | Type | Required | Description |
|---|---|---|---|
symbol | string | Yes | Asset ticker symbol (e.g., 'ETH', 'BTC') |
quantity | number | Yes | Number of units held |
purchaseDate | number | Yes | Unix timestamp in seconds |
purchasePrice | number | null | No | Price per unit at purchase |
asset_type | string | null | No | Asset classification (e.g., 'crypto') |
Was this helpful?