PortfolioClient
The PortfolioClient provides access to account balances, positions, exposure, and trade history.
Balances
Get All Balances
const balances = await client.portfolio.getBalances();
for (const balance of balances) {
console.log(`${balance.asset}: ${balance.available} available, ${balance.reserved} reserved`);
}
Get Specific Assets
const balances = await client.portfolio.getBalances(['BTC', 'ETH', 'USD']);
Get Single Asset Balance
const btc = await client.portfolio.getBalance('BTC');
console.log(btc);
// {
// asset: 'BTC',
// available: '5.5',
// reserved: '0.5',
// total: '6.0',
// usdValue: '300000.00'
// }
Positions
// Get all positions
const positions = await client.portfolio.getPositions();
// Get positions for specific asset
const btcPositions = await client.portfolio.getPositions('BTC');
for (const pos of positions) {
console.log(`${pos.asset}: ${pos.quantity} @ ${pos.averageEntryPrice}`);
console.log(` Current: ${pos.currentPrice}`);
console.log(` P&L: ${pos.unrealizedPnl} (${pos.unrealizedPnlPercent}%)`);
}
Portfolio Exposure
const exposure = await client.portfolio.getExposure();
console.log(`Total USD Value: ${exposure.totalUsdValue}`);
for (const position of exposure.positions) {
console.log(`${position.asset}: $${position.usdValue} (${position.percentage}%)`);
}
Portfolio Summary
const summary = await client.portfolio.getSummary();
console.log(summary);
// {
// totalValue: '500000.00',
// availableBalance: '100000.00',
// reservedBalance: '50000.00',
// unrealizedPnl: '25000.00',
// realizedPnl24h: '5000.00'
// }
P&L Breakdown
// Get P&L for different periods
const pnl24h = await client.portfolio.getPnL('24h');
const pnl7d = await client.portfolio.getPnL('7d');
const pnl30d = await client.portfolio.getPnL('30d');
console.log(pnl24h);
// {
// period: '24h',
// realizedPnl: '5000.00',
// unrealizedPnl: '2500.00',
// totalPnl: '7500.00',
// trades: 42
// }
Trade History
const trades = await client.portfolio.getTrades({
asset: 'BTC',
side: 'buy',
page: 1,
limit: 50,
});
for (const trade of trades.data) {
console.log(`${trade.side} ${trade.quantity} ${trade.asset} @ ${trade.price}`);
console.log(` Fee: ${trade.fee} ${trade.feeCurrency}`);
console.log(` Time: ${trade.timestamp}`);
}
// Pagination
if (trades.hasMore) {
const nextPage = await client.portfolio.getTrades({
page: trades.page + 1,
limit: 50,
});
}
Types
import type {
Balance,
Position,
Exposure,
PortfolioSummary,
PnLBreakdown,
Trade,
ListTradesParams,
} from 'zenotc';
Balance
| Field | Type | Description |
|---|---|---|
asset | string | Asset symbol |
available | string | Available balance |
reserved | string | Reserved (in orders) |
total | string | Total balance |
usdValue | string | USD equivalent |
Position
| Field | Type | Description |
|---|---|---|
asset | string | Asset symbol |
quantity | string | Position size |
averageEntryPrice | string | Average entry |
currentPrice | string | Current price |
unrealizedPnl | string | Unrealized P&L |
unrealizedPnlPercent | string | P&L percentage |
Trade
| Field | Type | Description |
|---|---|---|
id | string | Trade ID |
orderId | string | Parent order ID |
asset | string | Asset symbol |
side | 'buy' | 'sell' | Trade side |
quantity | string | Quantity filled |
price | string | Execution price |
fee | string | Fee amount |
feeCurrency | string | Fee currency |
timestamp | string | ISO timestamp |