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>
create-manual.ts
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`);
[@portabletext/react] Unknown block type "callout", specify a component for it in the `components.types` prop

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>
create-automatic.ts
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}`);

Manual vs Automatic

FeatureManualAutomatic
Holdings sourceUser-provided arrayDiscovered from wallet on-chain
Requires walletNoYes (wallet_address)
Holdings updateUser must update manuallySynced automatically
Chain scopingN/AOptional chain parameter
Use caseModel portfolios, watchlists, hypothetical allocationsTrack real wallet positions

Parameter Types

CreateManualPortfolioParams

FieldTypeRequiredDescription
namestringYesDisplay name for the portfolio
holdingsPortfolioHolding[]YesArray of holdings

CreateAutomaticPortfolioParams

FieldTypeRequiredDescription
namestringYesDisplay name for the portfolio
wallet_addressstringNoWallet address to track
chainstringNoChain to scope tracking (e.g., 'ethereum', 'polygon')

PortfolioHolding

FieldTypeRequiredDescription
symbolstringYesAsset ticker symbol (e.g., 'ETH', 'BTC')
quantitynumberYesNumber of units held
purchaseDatenumberYesUnix timestamp in seconds
purchasePricenumber | nullNoPrice per unit at purchase
asset_typestring | nullNoAsset classification (e.g., 'crypto')
Was this helpful?