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 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
</h1>
<div className="text-lg">
{platformData && formatChangeIndicator(changes24h.strategiesChange)}
{platformData && formatChangeIndicator(changesToday.strategiesChange)}
</div>
</div>
@@ -157,10 +157,10 @@ function PlatformSummary({index}: { index: number }) {
{formatCurrency(platformData?.totalPlatformVolume || 0)}
</div>
<div
className={`text-sm ${changes24h.volumeChange >= 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
<span className="ml-2 text-gray-400">
({formatPercentageChange(platformData?.totalPlatformVolume || 0, changes24h.volumeChange)})
({formatPercentageChange(platformData?.totalPlatformVolume || 0, changesToday.volumeChange)})
</span>
</div>
{/* Volume chart using daily snapshots */}
@@ -310,8 +310,8 @@ function PlatformSummary({index}: { index: number }) {
{formatNumber(platformData?.totalAgents || 0)}
</div>
<div
className={`text-sm ${changes24h.agentsChange >= 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)}
</div>
</div>
@@ -321,8 +321,8 @@ function PlatformSummary({index}: { index: number }) {
{formatNumber(platformData?.totalActiveStrategies || 0)}
</div>
<div
className={`text-sm ${changes24h.strategiesChange >= 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)}
</div>
</div>
@@ -333,8 +333,8 @@ function PlatformSummary({index}: { index: number }) {
{(platformData?.totalPlatformPnL || 0) >= 0 ? '+' : ''}{formatCurrency(platformData?.totalPlatformPnL || 0)}
</div>
<div
className={`text-sm ${changes24h.pnLChange >= 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
</div>
</div>
@@ -344,8 +344,8 @@ function PlatformSummary({index}: { index: number }) {
{formatCurrency(platformData?.openInterest || 0)}
</div>
<div
className={`text-sm ${changes24h.openInterestChange >= 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
</div>
</div>
</div>
@@ -358,8 +358,8 @@ function PlatformSummary({index}: { index: number }) {
{formatNumber(platformData?.totalPositionCount || 0)}
</div>
<div
className={`text-sm ${changes24h.positionCountChange >= 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)}
</div>
</div>