From 53f81302ba2de7f1da491cac5f6ce62ccb096494 Mon Sep 17 00:00:00 2001 From: cryptooda Date: Fri, 21 Nov 2025 17:02:18 +0700 Subject: [PATCH] Return last 24 volume for strategies --- .../Controllers/DataController.cs | 25 ++++++++++++++++--- .../src/generated/ManagingApi.ts | 1 + .../src/generated/ManagingApiTypes.ts | 1 + 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/Managing.Api/Controllers/DataController.cs b/src/Managing.Api/Controllers/DataController.cs index fb2474c0..959281fe 100644 --- a/src/Managing.Api/Controllers/DataController.cs +++ b/src/Managing.Api/Controllers/DataController.cs @@ -553,10 +553,6 @@ public class DataController : ControllerBase private async Task MapStrategyToViewModelAsync(Bot strategy, AgentBalanceHistory agentBalanceHistory, ITradingService tradingService) { - // Calculate volume statistics - decimal totalVolume = strategy.Volume; - decimal volumeLast24h = strategy.Volume; - // Use caching for position data in UI context (not critical trading operations) var cacheKey = $"positions_{strategy.Identifier}"; var cachedPositions = _cacheService.GetValue>(cacheKey); @@ -575,6 +571,27 @@ public class DataController : ControllerBase _cacheService.SaveValue(cacheKey, positions, TimeSpan.FromMinutes(2)); } + // Calculate volume statistics using cached positions + decimal totalVolume = strategy.Volume; + + // Use caching for volume calculation to avoid recalculation every time + var volumeCacheKey = $"volume_last24h_{strategy.Identifier}"; + var cachedVolume = _cacheService.GetValue(volumeCacheKey); + + decimal volumeLast24h; + if (cachedVolume != default(decimal)) + { + volumeLast24h = cachedVolume; + } + else + { + // Calculate volume for the last 24 hours + volumeLast24h = TradingBox.GetLast24HVolumeTraded(positions.ToDictionary(p => p.Identifier)); + + // Cache volume for 2 minutes for UI display purposes + _cacheService.SaveValue(volumeCacheKey, volumeLast24h, TimeSpan.FromMinutes(2)); + } + var positionsForMetrics = positions.Where(p => p.IsValidForMetrics()); // Calculate win/loss statistics from actual positions (including open positions) int wins = positionsForMetrics.Count(p => p.ProfitAndLoss != null && p.ProfitAndLoss.Realized > 0); diff --git a/src/Managing.WebApp/src/generated/ManagingApi.ts b/src/Managing.WebApp/src/generated/ManagingApi.ts index afa818fe..32792c88 100644 --- a/src/Managing.WebApp/src/generated/ManagingApi.ts +++ b/src/Managing.WebApp/src/generated/ManagingApi.ts @@ -5732,6 +5732,7 @@ export interface UserStrategyDetailsViewModel { identifier?: string; walletBalances?: { [key: string]: number; } | null; ticker?: Ticker; + masterAgentName?: string | null; } export interface PositionViewModel { diff --git a/src/Managing.WebApp/src/generated/ManagingApiTypes.ts b/src/Managing.WebApp/src/generated/ManagingApiTypes.ts index e2ed5656..717f376a 100644 --- a/src/Managing.WebApp/src/generated/ManagingApiTypes.ts +++ b/src/Managing.WebApp/src/generated/ManagingApiTypes.ts @@ -1198,6 +1198,7 @@ export interface UserStrategyDetailsViewModel { identifier?: string; walletBalances?: { [key: string]: number; } | null; ticker?: Ticker; + masterAgentName?: string | null; } export interface PositionViewModel {