Fix 24h changes

This commit is contained in:
2025-09-28 16:03:27 +07:00
parent 2d403da28f
commit fdb56dbb08

View File

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