Enhance UI, add AI integration, improve logging and database stats
This commit is contained in:
@@ -33,25 +33,26 @@ public class TraderAnalyticsWorker : BackgroundService
|
||||
_logger.LogError(ex, "Error in TraderAnalyticsWorker");
|
||||
}
|
||||
|
||||
_logger.LogInformation("TraderAnalyticsWorker sleeping for 12 hours...");
|
||||
await Task.Delay(TimeSpan.FromHours(12), ct);
|
||||
_logger.LogInformation("TraderAnalyticsWorker sleeping for 2 hours...");
|
||||
await Task.Delay(TimeSpan.FromHours(2), ct);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RunAnalyticsAsync(CancellationToken ct)
|
||||
{
|
||||
using var scope = _services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
var pnlEngine = scope.ServiceProvider.GetRequiredService<IPositionPnLEngine>();
|
||||
|
||||
var cutoff30d = DateTime.UtcNow.AddDays(-30);
|
||||
List<int> traderIds;
|
||||
|
||||
// Find traders active in the last 30 days
|
||||
var traderIds = await db.Trades
|
||||
.Where(t => t.ExecutedAt >= cutoff30d)
|
||||
.Select(t => t.TraderId)
|
||||
.Distinct()
|
||||
.ToListAsync(ct);
|
||||
using (var scope = _services.CreateScope())
|
||||
{
|
||||
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
// Find traders active in the last 30 days
|
||||
traderIds = await db.Trades
|
||||
.Where(t => t.ExecutedAt >= cutoff30d)
|
||||
.Select(t => t.TraderId)
|
||||
.Distinct()
|
||||
.ToListAsync(ct);
|
||||
}
|
||||
|
||||
_logger.LogInformation("Found {Count} active traders to analyze", traderIds.Count);
|
||||
|
||||
@@ -59,6 +60,8 @@ public class TraderAnalyticsWorker : BackgroundService
|
||||
{
|
||||
try
|
||||
{
|
||||
using var traderScope = _services.CreateScope();
|
||||
var pnlEngine = traderScope.ServiceProvider.GetRequiredService<IPositionPnLEngine>();
|
||||
await pnlEngine.RecalculateTraderPositionsAsync(id, ct);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user