Return last 24 volume for strategies
This commit is contained in:
@@ -553,10 +553,6 @@ public class DataController : ControllerBase
|
||||
private async Task<UserStrategyDetailsViewModel> 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<List<Position>>(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<decimal>(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);
|
||||
|
||||
@@ -5732,6 +5732,7 @@ export interface UserStrategyDetailsViewModel {
|
||||
identifier?: string;
|
||||
walletBalances?: { [key: string]: number; } | null;
|
||||
ticker?: Ticker;
|
||||
masterAgentName?: string | null;
|
||||
}
|
||||
|
||||
export interface PositionViewModel {
|
||||
|
||||
@@ -1198,6 +1198,7 @@ export interface UserStrategyDetailsViewModel {
|
||||
identifier?: string;
|
||||
walletBalances?: { [key: string]: number; } | null;
|
||||
ticker?: Ticker;
|
||||
masterAgentName?: string | null;
|
||||
}
|
||||
|
||||
export interface PositionViewModel {
|
||||
|
||||
Reference in New Issue
Block a user