diff --git a/frontend/src/pages/DashboardPage.tsx b/frontend/src/pages/DashboardPage.tsx index fd0f42d..93c5bd1 100644 --- a/frontend/src/pages/DashboardPage.tsx +++ b/frontend/src/pages/DashboardPage.tsx @@ -3,7 +3,7 @@ import { Link } from 'react-router-dom'; import { useActivation } from '../hooks/useActivation'; import { useTrades } from '../hooks/useTrades'; import { useWatchlist } from '../hooks/useWatchlist'; -import { usePerformance } from '../hooks/usePerformance'; +import { usePaperTrades } from '../hooks/usePaperTrades'; import { useMarketRegime } from '../hooks/useMarketRegime'; import { regimeColor, regimeDot, regimeHeadline } from '../lib/regime'; import { Callout } from '../components/ui/Callout'; @@ -11,6 +11,7 @@ import { Section } from '../components/ui/Section'; import { OpenTradesPanel } from '../components/dashboard/OpenTradesPanel'; import { SkeletonCard, SkeletonTable } from '../components/ui/Skeleton'; import { formatPrice } from '../lib/format'; +import { tradePnl } from '../lib/paperTrade'; import { recommendationActionLabel } from '../lib/recommendation'; import { qualifiesSetup, activationSummary, primaryTargetProbability } from '../lib/qualification'; import type { TradeSetup } from '../lib/types'; @@ -27,6 +28,11 @@ function rColor(value: number | null): string { return 'text-gray-300'; } +function money(value: number): string { + const sign = value >= 0 ? '+' : '−'; + return `${sign}$${Math.abs(value).toFixed(2)}`; +} + function Metric({ label, value, sub, valueClass = 'text-gray-100' }: { label: string; value: string; @@ -57,7 +63,7 @@ export default function DashboardPage() { const trades = useTrades(); const watchlist = useWatchlist(); const activation = useActivation(); - const performance = usePerformance(); + const openTrades = usePaperTrades('open'); const regime = useMarketRegime(); const qualifiedSetups = useMemo( @@ -90,7 +96,21 @@ export default function DashboardPage() { weekday: 'long', month: 'long', day: 'numeric', }); - const stats = performance.data?.overall; + // Current exposure from open paper trades: $ at risk to stops + mark-to-market. + const exposure = useMemo(() => { + const rows = openTrades.data ?? []; + let riskUsd = 0, unrealUsd = 0, unrealR = 0, rPriced = 0, winners = 0, losers = 0; + for (const t of rows) { + riskUsd += Math.abs(t.entry_price - t.stop_loss) * t.shares; + const p = tradePnl(t); + if (!p) continue; + unrealUsd += p.pnl; + if (p.r != null) { unrealR += p.r; rPriced += 1; } + if (p.pnl > 0) winners += 1; + else if (p.pnl < 0) losers += 1; + } + return { count: rows.length, riskUsd, unrealUsd, unrealR, rPriced, winners, losers }; + }, [openTrades.data]); return (