import { useData, usePublish, type PanelRef } from '@jaspers-ai/sdk' import { fmt, sign } from './format' import './styles.css' interface Account { mode: string account_number: string | null status: string | null equity: number | null cash: number | null buying_power: number | null day_pl: number | null day_pl_pct: number | null portfolio_value: number | null trading_blocked: boolean pattern_day_trader: boolean daytrade_count: number | null } interface Position { symbol: string side: string | null qty: number | null avg_entry_price: number | null current_price: number | null market_value: number | null unrealized_pl: number | null unrealized_plpc: number | null change_today: number | null } export function AccountPanel({ panel }: { panel: PanelRef }) { const state = useData(`workspaces/${panel.workspaceId}/panels/${panel.id}/state`) as | { live_account?: boolean } | undefined if (state === undefined) return
Loading…
return{acct.error}
) : !a ? (Loading…
) : ({pos.error}
) : !pos.data ? null : rows.length === 0 ? (No open positions.
) : (| Symbol | Side | Qty | Avg entry | Price | Market value | Unrealized P/L | P/L % | Today % |
|---|---|---|---|---|---|---|---|---|
| {p.symbol} | {p.side ?? '–'} | {fmt(p.qty, 0)} | {fmt(p.avg_entry_price)} | {fmt(p.current_price)} | {fmt(p.market_value)} | {fmt(p.unrealized_pl)} | {p.unrealized_plpc === null ? '–' : `${fmt(p.unrealized_plpc * 100)}%`} | {p.change_today === null ? '–' : `${fmt(p.change_today * 100)}%`} |