投资组合仪表盘
投资组合仪表盘提供所有 AI 交易订单的汇总视图,包括总投入资金、当前 NAV、盈亏以及按策略分类的明细。在 React 中可使用 useAIPortfolio hook,在任何平台上可使用 getAIPortfolio API 方法。
useAIPortfolio Hook
import { useAIPortfolio } from '@one_deploy/sdk';
import type { UseAIPortfolioResult } from '@one_deploy/sdk';
UseAIPortfolioResult
interface UseAIPortfolioResult {
/** Aggregated portfolio summary. Null until the first successful fetch. */
portfolio: AIPortfolioSummary | null;
/** True while the initial fetch is in progress. */
isLoading: boolean;
/** Error object if the fetch failed, otherwise null. */
error: Error | null;
/** Re-fetch portfolio data. */
refetch: () => Promise<void>;
}
基本用法
import { useAIPortfolio } from '@one_deploy/sdk';
function PortfolioDashboard() {
const { portfolio, isLoading, error, refetch } = useAIPortfolio();
if (isLoading) return <Text>Loading portfolio...</Text>;
if (error) return <Text>Error: {error.message}</Text>;
if (!portfolio) return <Text>No portfolio data</Text>;
return (
<View style={styles.container}>
<Text style={styles.heading}>AI Trading Portfolio</Text>
<View style={styles.statsRow}>
<StatCard label="Total Invested" value={`$${portfolio.totalInvested.toFixed(2)}`} />
<StatCard label="Current NAV" value={`$${portfolio.currentNav.toFixed(2)}`} />
</View>
<View style={styles.statsRow}>
<StatCard
label="Total P&L"
value={`${portfolio.totalPnl >= 0 ? '+' : ''}$${portfolio.totalPnl.toFixed(2)}`}
/>
<StatCard
label="Return"
value={`${portfolio.totalPnlPercent >= 0 ? '+' : ''}${portfolio.totalPnlPercent.toFixed(2)}%`}
/>
</View>
<View style={styles.statsRow}>
<StatCard label="Active Orders" value={String(portfolio.activeOrders)} />
<StatCard label="Completed" value={String(portfolio.completedOrders)} />
</View>
<Pressable onPress={refetch}>
<Text style={styles.refreshButton}>Refresh</Text>
</Pressable>
</View>
);
}
AIPortfolioSummary 类型
interface AIPortfolioSummary {
/** Total capital invested across all orders (in USD). */
totalInvested: number;
/** Current total net asset value across all active orders. */
currentNav: number;
/** Total profit/loss amount (currentNav - totalInvested for active orders + realised P&L). */
totalPnl: number;
/** Total profit/loss as a percentage. */
totalPnlPercent: number;
/** Number of currently active orders. */
activeOrders: number;
/** Number of completed orders (cycle ended). */
completedOrders: number;
/** Number of redeemed orders (early withdrawal). */
redeemedOrders: number;
/** Number of paused orders. */
pausedOrders: number;
/** Per-strategy breakdown. */
strategyBreakdown: AIStrategyBreakdown[];
/** Per-chain breakdown. */
chainBreakdown: AIChainBreakdown[];
/** Historical daily NAV snapshots for portfolio-level charting. */
navHistory: AINavSnapshot[];
}
interface AIStrategyBreakdown {
strategyId: string;
strategyName: string;
category: StrategyCategory;
invested: number;
currentNav: number;
pnl: number;
pnlPercent: number;
orderCount: number;
}
interface AIChainBreakdown {
chainId: number;
chainName: string;
invested: number;
currentNav: number;
pnl: number;
orderCount: number;
}