diff --git a/src/Managing.WebApp/src/pages/dashboardPage/platformSummary.tsx b/src/Managing.WebApp/src/pages/dashboardPage/platformSummary.tsx index 9f073eff..46171a6e 100644 --- a/src/Managing.WebApp/src/pages/dashboardPage/platformSummary.tsx +++ b/src/Managing.WebApp/src/pages/dashboardPage/platformSummary.tsx @@ -26,9 +26,9 @@ function PlatformSummary({index}: { index: number }) { const topStrategiesByRoi = data?.topStrategiesByRoi const topAgentsByPnL = data?.topAgentsByPnL - // Calculate 24-hour changes from daily snapshots - const changes24h = useMemo(() => { - if (!platformData?.dailySnapshots || platformData.dailySnapshots.length < 2) { + // Calculate changes since last snapshot (today's changes) + const changesToday = useMemo(() => { + if (!platformData?.dailySnapshots || platformData.dailySnapshots.length === 0) { return { agentsChange: 0, strategiesChange: 0, @@ -44,18 +44,18 @@ function PlatformSummary({index}: { index: number }) { new Date(b.date || 0).getTime() - new Date(a.date || 0).getTime() ) - const latest = sortedSnapshots[0] - const previous = sortedSnapshots[1] + const latestSnapshot = sortedSnapshots[0] + // Compare current data with the latest snapshot to get today's changes return { - agentsChange: (latest.totalAgents || 0) - (previous.totalAgents || 0), - strategiesChange: (latest.totalStrategies || 0) - (previous.totalStrategies || 0), - volumeChange: (latest.totalVolume || 0) - (previous.totalVolume || 0), - pnLChange: (latest.totalPnL || 0) - (previous.totalPnL || 0), - openInterestChange: (latest.totalOpenInterest || 0) - (previous.totalOpenInterest || 0), - positionCountChange: (latest.totalPositionCount || 0) - (previous.totalPositionCount || 0) + agentsChange: (platformData.totalAgents || 0) - (latestSnapshot.totalAgents || 0), + strategiesChange: (platformData.totalActiveStrategies || 0) - (latestSnapshot.totalStrategies || 0), + volumeChange: (platformData.totalPlatformVolume || 0) - (latestSnapshot.totalVolume || 0), + pnLChange: (platformData.totalPlatformPnL || 0) - (latestSnapshot.totalPnL || 0), + openInterestChange: (platformData.openInterest || 0) - (latestSnapshot.totalOpenInterest || 0), + positionCountChange: (platformData.totalPositionCount || 0) - (latestSnapshot.totalPositionCount || 0) } - }, [platformData?.dailySnapshots]) + }, [platformData]) const formatCurrency = (value: number) => { if (value >= 1000000) { @@ -144,7 +144,7 @@ function PlatformSummary({index}: { index: number }) { {formatNumber(platformData?.totalActiveStrategies || 0)} Strategies Deployed
- {platformData && formatChangeIndicator(changes24h.strategiesChange)} + {platformData && formatChangeIndicator(changesToday.strategiesChange)}
@@ -157,10 +157,10 @@ function PlatformSummary({index}: { index: number }) { {formatCurrency(platformData?.totalPlatformVolume || 0)}
= 0 ? 'text-green-500' : 'text-red-500'}`}> - {changes24h.volumeChange >= 0 ? '+' : ''}{formatCurrency(changes24h.volumeChange)} Today + className={`text-sm ${changesToday.volumeChange >= 0 ? 'text-green-500' : 'text-red-500'}`}> + {changesToday.volumeChange >= 0 ? '+' : ''}{formatCurrency(changesToday.volumeChange)} Today - ({formatPercentageChange(platformData?.totalPlatformVolume || 0, changes24h.volumeChange)}) + ({formatPercentageChange(platformData?.totalPlatformVolume || 0, changesToday.volumeChange)})
{/* Volume chart using daily snapshots */} @@ -310,8 +310,8 @@ function PlatformSummary({index}: { index: number }) { {formatNumber(platformData?.totalAgents || 0)}
= 0 ? 'text-green-500' : 'text-red-500'}`}> - {formatChangeIndicator(changes24h.agentsChange)} + className={`text-sm ${changesToday.agentsChange >= 0 ? 'text-green-500' : 'text-red-500'}`}> + {formatChangeIndicator(changesToday.agentsChange)}
@@ -321,8 +321,8 @@ function PlatformSummary({index}: { index: number }) { {formatNumber(platformData?.totalActiveStrategies || 0)}
= 0 ? 'text-green-500' : 'text-red-500'}`}> - {formatChangeIndicator(changes24h.strategiesChange)} + className={`text-sm ${changesToday.strategiesChange >= 0 ? 'text-green-500' : 'text-red-500'}`}> + {formatChangeIndicator(changesToday.strategiesChange)}
@@ -333,8 +333,8 @@ function PlatformSummary({index}: { index: number }) { {(platformData?.totalPlatformPnL || 0) >= 0 ? '+' : ''}{formatCurrency(platformData?.totalPlatformPnL || 0)}
= 0 ? 'text-green-500' : 'text-red-500'}`}> - {changes24h.pnLChange >= 0 ? '+' : ''}{formatCurrency(changes24h.pnLChange)} Today + className={`text-sm ${changesToday.pnLChange >= 0 ? 'text-green-500' : 'text-red-500'}`}> + {changesToday.pnLChange >= 0 ? '+' : ''}{formatCurrency(changesToday.pnLChange)} Today
@@ -344,8 +344,8 @@ function PlatformSummary({index}: { index: number }) { {formatCurrency(platformData?.openInterest || 0)}
= 0 ? 'text-green-500' : 'text-red-500'}`}> - {changes24h.openInterestChange >= 0 ? '+' : ''}{formatCurrency(changes24h.openInterestChange)} Today + className={`text-sm ${changesToday.openInterestChange >= 0 ? 'text-green-500' : 'text-red-500'}`}> + {changesToday.openInterestChange >= 0 ? '+' : ''}{formatCurrency(changesToday.openInterestChange)} Today
@@ -358,8 +358,8 @@ function PlatformSummary({index}: { index: number }) { {formatNumber(platformData?.totalPositionCount || 0)}
= 0 ? 'text-green-500' : 'text-red-500'}`}> - {formatChangeIndicator(changes24h.positionCountChange)} + className={`text-sm ${changesToday.positionCountChange >= 0 ? 'text-green-500' : 'text-red-500'}`}> + {formatChangeIndicator(changesToday.positionCountChange)}