Fix dailySnapshot for platformsummary
This commit is contained in:
@@ -4096,6 +4096,7 @@ export interface LightBacktest {
|
||||
sharpeRatio?: number | null;
|
||||
score?: number;
|
||||
scoreMessage?: string | null;
|
||||
metadata?: any | null;
|
||||
}
|
||||
|
||||
export interface RunBacktestRequest {
|
||||
@@ -4533,7 +4534,6 @@ export interface UserStrategyDetailsViewModel {
|
||||
state?: BotStatus;
|
||||
pnL?: number;
|
||||
roiPercentage?: number;
|
||||
roiLast24H?: number;
|
||||
runtime?: Date;
|
||||
winRate?: number;
|
||||
totalVolumeTraded?: number;
|
||||
@@ -4547,30 +4547,30 @@ export interface UserStrategyDetailsViewModel {
|
||||
}
|
||||
|
||||
export interface PlatformSummaryViewModel {
|
||||
lastUpdated?: Date;
|
||||
lastSnapshot?: Date;
|
||||
hasPendingChanges?: boolean;
|
||||
totalAgents?: number;
|
||||
totalActiveStrategies?: number;
|
||||
totalPlatformPnL?: number;
|
||||
totalPlatformVolume?: number;
|
||||
totalPlatformVolumeLast24h?: number;
|
||||
totalOpenInterest?: number;
|
||||
openInterest?: number;
|
||||
totalPositionCount?: number;
|
||||
agentsChange24h?: number;
|
||||
strategiesChange24h?: number;
|
||||
pnLChange24h?: number;
|
||||
volumeChange24h?: number;
|
||||
openInterestChange24h?: number;
|
||||
positionCountChange24h?: number;
|
||||
totalPlatformFees?: number;
|
||||
dailySnapshots?: DailySnapshot[] | null;
|
||||
volumeByAsset?: { [key in keyof typeof Ticker]?: number; } | null;
|
||||
positionCountByAsset?: { [key in keyof typeof Ticker]?: number; } | null;
|
||||
positionCountByDirection?: { [key in keyof typeof TradeDirection]?: number; } | null;
|
||||
lastUpdated?: Date;
|
||||
last24HourSnapshot?: Date;
|
||||
volumeHistory?: VolumeHistoryPoint[] | null;
|
||||
}
|
||||
|
||||
export interface VolumeHistoryPoint {
|
||||
export interface DailySnapshot {
|
||||
date?: Date;
|
||||
volume?: number;
|
||||
totalAgents?: number;
|
||||
totalStrategies?: number;
|
||||
totalVolume?: number;
|
||||
totalPnL?: number;
|
||||
totalOpenInterest?: number;
|
||||
totalPositionCount?: number;
|
||||
}
|
||||
|
||||
export interface PaginatedAgentIndexResponse {
|
||||
|
||||
@@ -544,6 +544,7 @@ export interface LightBacktest {
|
||||
sharpeRatio?: number | null;
|
||||
score?: number;
|
||||
scoreMessage?: string | null;
|
||||
metadata?: any | null;
|
||||
}
|
||||
|
||||
export interface RunBacktestRequest {
|
||||
@@ -981,7 +982,6 @@ export interface UserStrategyDetailsViewModel {
|
||||
state?: BotStatus;
|
||||
pnL?: number;
|
||||
roiPercentage?: number;
|
||||
roiLast24H?: number;
|
||||
runtime?: Date;
|
||||
winRate?: number;
|
||||
totalVolumeTraded?: number;
|
||||
@@ -995,30 +995,30 @@ export interface UserStrategyDetailsViewModel {
|
||||
}
|
||||
|
||||
export interface PlatformSummaryViewModel {
|
||||
lastUpdated?: Date;
|
||||
lastSnapshot?: Date;
|
||||
hasPendingChanges?: boolean;
|
||||
totalAgents?: number;
|
||||
totalActiveStrategies?: number;
|
||||
totalPlatformPnL?: number;
|
||||
totalPlatformVolume?: number;
|
||||
totalPlatformVolumeLast24h?: number;
|
||||
totalOpenInterest?: number;
|
||||
openInterest?: number;
|
||||
totalPositionCount?: number;
|
||||
agentsChange24h?: number;
|
||||
strategiesChange24h?: number;
|
||||
pnLChange24h?: number;
|
||||
volumeChange24h?: number;
|
||||
openInterestChange24h?: number;
|
||||
positionCountChange24h?: number;
|
||||
totalPlatformFees?: number;
|
||||
dailySnapshots?: DailySnapshot[] | null;
|
||||
volumeByAsset?: { [key in keyof typeof Ticker]?: number; } | null;
|
||||
positionCountByAsset?: { [key in keyof typeof Ticker]?: number; } | null;
|
||||
positionCountByDirection?: { [key in keyof typeof TradeDirection]?: number; } | null;
|
||||
lastUpdated?: Date;
|
||||
last24HourSnapshot?: Date;
|
||||
volumeHistory?: VolumeHistoryPoint[] | null;
|
||||
}
|
||||
|
||||
export interface VolumeHistoryPoint {
|
||||
export interface DailySnapshot {
|
||||
date?: Date;
|
||||
volume?: number;
|
||||
totalAgents?: number;
|
||||
totalStrategies?: number;
|
||||
totalVolume?: number;
|
||||
totalPnL?: number;
|
||||
totalOpenInterest?: number;
|
||||
totalPositionCount?: number;
|
||||
}
|
||||
|
||||
export interface PaginatedAgentIndexResponse {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React from 'react'
|
||||
import React, {useMemo} from 'react'
|
||||
import {useQuery, useQueryClient} from '@tanstack/react-query'
|
||||
import useApiUrlStore from '../../app/store/apiStore'
|
||||
import {fetchPlatformData} from '../../services/platformService'
|
||||
@@ -26,6 +26,37 @@ 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) {
|
||||
return {
|
||||
agentsChange: 0,
|
||||
strategiesChange: 0,
|
||||
volumeChange: 0,
|
||||
pnLChange: 0,
|
||||
openInterestChange: 0,
|
||||
positionCountChange: 0
|
||||
}
|
||||
}
|
||||
|
||||
// Sort snapshots by date (most recent first)
|
||||
const sortedSnapshots = [...platformData.dailySnapshots].sort((a, b) =>
|
||||
new Date(b.date || 0).getTime() - new Date(a.date || 0).getTime()
|
||||
)
|
||||
|
||||
const latest = sortedSnapshots[0]
|
||||
const previous = sortedSnapshots[1]
|
||||
|
||||
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)
|
||||
}
|
||||
}, [platformData?.dailySnapshots])
|
||||
|
||||
const formatCurrency = (value: number) => {
|
||||
if (value >= 1000000) {
|
||||
return `$${(value / 1000000).toFixed(2)}M`
|
||||
@@ -113,7 +144,7 @@ function PlatformSummary({index}: { index: number }) {
|
||||
{formatNumber(platformData?.totalActiveStrategies || 0)} Strategies Deployed
|
||||
</h1>
|
||||
<div className="text-lg">
|
||||
{platformData && formatChangeIndicator(platformData.strategiesChange24h || 0)}
|
||||
{platformData && formatChangeIndicator(changes24h.strategiesChange)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -126,15 +157,33 @@ function PlatformSummary({index}: { index: number }) {
|
||||
{formatCurrency(platformData?.totalPlatformVolume || 0)}
|
||||
</div>
|
||||
<div
|
||||
className={`text-sm ${(platformData?.volumeChange24h || 0) >= 0 ? 'text-green-500' : 'text-red-500'}`}>
|
||||
{(platformData?.volumeChange24h || 0) >= 0 ? '+' : ''}{formatCurrency(platformData?.volumeChange24h || 0)} Today
|
||||
className={`text-sm ${changes24h.volumeChange >= 0 ? 'text-green-500' : 'text-red-500'}`}>
|
||||
{changes24h.volumeChange >= 0 ? '+' : ''}{formatCurrency(changes24h.volumeChange)} Today
|
||||
<span className="ml-2 text-gray-400">
|
||||
({formatPercentageChange(platformData?.totalPlatformVolume || 0, platformData?.volumeChange24h || 0)})
|
||||
({formatPercentageChange(platformData?.totalPlatformVolume || 0, changes24h.volumeChange)})
|
||||
</span>
|
||||
</div>
|
||||
{/* Simple chart placeholder - you can replace with actual chart */}
|
||||
<div className="mt-4 h-16 flex items-end">
|
||||
<div className="w-full h-8 bg-green-500 rounded opacity-20"></div>
|
||||
{/* Volume chart using daily snapshots */}
|
||||
<div className="mt-4 h-16 flex items-end gap-1">
|
||||
{platformData?.dailySnapshots && platformData.dailySnapshots.length > 0 ? (
|
||||
[...platformData.dailySnapshots]
|
||||
.sort((a, b) => new Date(a.date || 0).getTime() - new Date(b.date || 0).getTime())
|
||||
.slice(-7) // Last 7 days
|
||||
.map((snapshot, index) => {
|
||||
const maxVolume = Math.max(...platformData.dailySnapshots?.map(s => s.totalVolume || 0) || [0])
|
||||
const height = maxVolume > 0 ? ((snapshot.totalVolume || 0) / maxVolume) * 100 : 0
|
||||
return (
|
||||
<div
|
||||
key={index}
|
||||
className="flex-1 bg-green-500 rounded-sm opacity-60 hover:opacity-80 transition-opacity"
|
||||
style={{ height: `${Math.max(height, 4)}%` }}
|
||||
title={`${new Date(snapshot.date || 0).toLocaleDateString()}: ${formatCurrency(snapshot.totalVolume || 0)}`}
|
||||
/>
|
||||
)
|
||||
})
|
||||
) : (
|
||||
<div className="w-full h-8 bg-green-500 rounded opacity-20"></div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -261,8 +310,8 @@ function PlatformSummary({index}: { index: number }) {
|
||||
{formatNumber(platformData?.totalAgents || 0)}
|
||||
</div>
|
||||
<div
|
||||
className={`text-sm ${(platformData?.agentsChange24h || 0) >= 0 ? 'text-green-500' : 'text-red-500'}`}>
|
||||
{formatChangeIndicator(platformData?.agentsChange24h || 0)}
|
||||
className={`text-sm ${changes24h.agentsChange >= 0 ? 'text-green-500' : 'text-red-500'}`}>
|
||||
{formatChangeIndicator(changes24h.agentsChange)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -272,8 +321,8 @@ function PlatformSummary({index}: { index: number }) {
|
||||
{formatNumber(platformData?.totalActiveStrategies || 0)}
|
||||
</div>
|
||||
<div
|
||||
className={`text-sm ${(platformData?.strategiesChange24h || 0) >= 0 ? 'text-green-500' : 'text-red-500'}`}>
|
||||
{formatChangeIndicator(platformData?.strategiesChange24h || 0)}
|
||||
className={`text-sm ${changes24h.strategiesChange >= 0 ? 'text-green-500' : 'text-red-500'}`}>
|
||||
{formatChangeIndicator(changes24h.strategiesChange)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -284,19 +333,19 @@ function PlatformSummary({index}: { index: number }) {
|
||||
{(platformData?.totalPlatformPnL || 0) >= 0 ? '+' : ''}{formatCurrency(platformData?.totalPlatformPnL || 0)}
|
||||
</div>
|
||||
<div
|
||||
className={`text-sm ${(platformData?.pnLChange24h || 0) >= 0 ? 'text-green-500' : 'text-red-500'}`}>
|
||||
{(platformData?.pnLChange24h || 0) >= 0 ? '+' : ''}{formatCurrency(platformData?.pnLChange24h || 0)} Today
|
||||
className={`text-sm ${changes24h.pnLChange >= 0 ? 'text-green-500' : 'text-red-500'}`}>
|
||||
{changes24h.pnLChange >= 0 ? '+' : ''}{formatCurrency(changes24h.pnLChange)} Today
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-base-200 rounded-lg p-6">
|
||||
<h3 className="text-lg font-semibold text-gray-400 mb-2">Open Interest</h3>
|
||||
<div className="text-3xl font-bold text-white mb-1">
|
||||
{formatCurrency(platformData?.totalOpenInterest || 0)}
|
||||
{formatCurrency(platformData?.openInterest || 0)}
|
||||
</div>
|
||||
<div
|
||||
className={`text-sm ${(platformData?.openInterestChange24h || 0) >= 0 ? 'text-green-500' : 'text-red-500'}`}>
|
||||
{(platformData?.openInterestChange24h || 0) >= 0 ? '+' : ''}{formatCurrency(platformData?.openInterestChange24h || 0)} Today
|
||||
className={`text-sm ${changes24h.openInterestChange >= 0 ? 'text-green-500' : 'text-red-500'}`}>
|
||||
{changes24h.openInterestChange >= 0 ? '+' : ''}{formatCurrency(changes24h.openInterestChange)} Today
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -309,8 +358,8 @@ function PlatformSummary({index}: { index: number }) {
|
||||
{formatNumber(platformData?.totalPositionCount || 0)}
|
||||
</div>
|
||||
<div
|
||||
className={`text-sm ${(platformData?.positionCountChange24h || 0) >= 0 ? 'text-green-500' : 'text-red-500'}`}>
|
||||
{formatChangeIndicator(platformData?.positionCountChange24h || 0)}
|
||||
className={`text-sm ${changes24h.positionCountChange >= 0 ? 'text-green-500' : 'text-red-500'}`}>
|
||||
{formatChangeIndicator(changes24h.positionCountChange)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -445,7 +494,7 @@ function PlatformSummary({index}: { index: number }) {
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
<span>24h snapshot: {platformData?.last24HourSnapshot ? new Date(platformData.last24HourSnapshot).toLocaleString() : 'Unknown'}</span>
|
||||
<span>Last snapshot: {platformData?.lastSnapshot ? new Date(platformData.lastSnapshot).toLocaleString() : 'Unknown'}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user