Add cache for position
This commit is contained in:
@@ -480,8 +480,23 @@ public class DataController : ControllerBase
|
||||
decimal totalVolume = strategy.Volume;
|
||||
decimal volumeLast24h = strategy.Volume;
|
||||
|
||||
// Fetch positions associated with this bot using the provided trading service
|
||||
var positions = await tradingService.GetPositionsByInitiatorIdentifierAsync(strategy.Identifier);
|
||||
// Use caching for position data in UI context (not critical trading operations)
|
||||
var cacheKey = $"positions_{strategy.Identifier}";
|
||||
var cachedPositions = _cacheService.GetValue<List<Position>>(cacheKey);
|
||||
|
||||
List<Position> positions;
|
||||
if (cachedPositions != null)
|
||||
{
|
||||
positions = cachedPositions;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fetch positions associated with this bot using the provided trading service
|
||||
positions = (await tradingService.GetPositionsByInitiatorIdentifierAsync(strategy.Identifier)).ToList();
|
||||
|
||||
// Cache positions for 2 minutes for UI display purposes
|
||||
_cacheService.SaveValue(cacheKey, positions, TimeSpan.FromMinutes(2));
|
||||
}
|
||||
|
||||
// Calculate win/loss statistics from actual positions (including open positions)
|
||||
int wins = positions.Count(p => p.ProfitAndLoss != null && p.ProfitAndLoss.Realized > 0);
|
||||
|
||||
Reference in New Issue
Block a user