Implement A3, A4, A5, B3: Add MarketOutcomePriceSnapshot, implement Polymarket CLOB prices-history endpoint, improve strategy classification, introduce CopytradingScore, and decouple/optimize scoring pipeline into a separate worker

This commit is contained in:
Richard
2026-07-03 11:20:28 +02:00
parent e994e1ce72
commit f8c8230d99
21 changed files with 2035 additions and 22 deletions
@@ -17,6 +17,7 @@ public static class DependencyInjection
services.AddHostedService<ReportingWorker>();
services.AddHostedService<TraderCleanupWorker>();
services.AddHostedService<TraderAnalyticsWorker>();
services.AddHostedService<ScoringAndAlertsWorker>();
return services;
}
}
@@ -154,14 +154,7 @@ public class PollingWorker : BackgroundService
}
}
// Recalculate scores and evaluate alerts
using (var scope = _services.CreateScope())
{
var scoringService = scope.ServiceProvider.GetRequiredService<IScoringService>();
var alertService = scope.ServiceProvider.GetRequiredService<IAlertService>();
await scoringService.RecalculateAllScoresAsync(stoppingToken);
await alertService.EvaluateAlertsAsync(stoppingToken);
}
_logger.LogWarning("✅ Polling cycle complete. Next in 60s.");
}
@@ -0,0 +1,63 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Predictalytics.Application.Interfaces;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Predictalytics.Worker.Services;
/// <summary>
/// Background service that periodically recalculates scores and ranks for all traders
/// and evaluates system alerts. Decoupled from the 60-second polling cycle.
/// </summary>
public class ScoringAndAlertsWorker : BackgroundService
{
private readonly IServiceProvider _services;
private readonly ILogger<ScoringAndAlertsWorker> _logger;
private readonly TimeSpan _checkInterval = TimeSpan.FromMinutes(15);
public ScoringAndAlertsWorker(IServiceProvider services, ILogger<ScoringAndAlertsWorker> logger)
{
_services = services;
_logger = logger;
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
_logger.LogInformation("📈 ScoringAndAlertsWorker started (recalculation interval: {Interval}m)", _checkInterval.TotalMinutes);
await Task.Delay(10000, stoppingToken); // Let system initialize
while (!stoppingToken.IsCancellationRequested)
{
try
{
_logger.LogInformation("📈 ScoringAndAlertsWorker: Starting recalculation cycle...");
using (var scope = _services.CreateScope())
{
var scoringService = scope.ServiceProvider.GetRequiredService<IScoringService>();
var alertService = scope.ServiceProvider.GetRequiredService<IAlertService>();
await scoringService.RecalculateAllScoresAsync(stoppingToken);
await alertService.EvaluateAlertsAsync(stoppingToken);
}
_logger.LogInformation("📈 ScoringAndAlertsWorker: Recalculation cycle complete.");
}
catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
{
// App shutting down
}
catch (Exception ex)
{
_logger.LogError(ex, "Error in ScoringAndAlertsWorker execution cycle");
}
await Task.Delay(_checkInterval, stoppingToken);
}
_logger.LogInformation("📈 ScoringAndAlertsWorker stopped");
}
}