Add tracking for analyzed traders and add crawling configuration to appsettings.json

This commit is contained in:
Richard
2026-07-07 09:45:51 +02:00
parent 2c7c643fdb
commit 910d25159a
8 changed files with 47 additions and 2 deletions
@@ -8,6 +8,7 @@ public interface IPlatformStatisticsService
void TrackTraderDiscovery(PlatformType platform, int count = 1);
void TrackTradeActivity(PlatformType platform, int count = 1);
void TrackDuplicateError(PlatformType platform, int count = 1);
void TrackTradersAnalyzed(PlatformType platform, int count = 1);
Dictionary<PlatformType, PlatformStats> GetAndResetStats();
}
@@ -18,4 +19,5 @@ public class PlatformStats
public int TradersDiscovered { get; set; }
public int TradesProcessed { get; set; }
public int DuplicateErrors { get; set; }
public int TradersAnalyzed { get; set; }
}
@@ -32,6 +32,12 @@ public class PlatformStatisticsService : IPlatformStatisticsService
lock (stats) stats.DuplicateErrors += count;
}
public void TrackTradersAnalyzed(PlatformType platform, int count = 1)
{
var stats = _stats.GetOrAdd(platform, _ => new PlatformStats());
lock (stats) stats.TradersAnalyzed += count;
}
public Dictionary<PlatformType, PlatformStats> GetAndResetStats()
{
var result = new Dictionary<PlatformType, PlatformStats>();
@@ -17,5 +17,16 @@
"BaseUrl": "https://openrouter.ai/api/v1",
"DefaultModel": "google/gemini-flash-1.5",
"ManualAnalysisModel": "anthropic/claude-3-opus"
},
"PlatformSettings": {
"Polymarket": {
"EnableCrawling": true
},
"Limitless": {
"EnableCrawling": false
},
"Azuro": {
"EnableCrawling": false
}
}
}
@@ -3,6 +3,7 @@ using Predictalytics.Domain.Enums;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
namespace Predictalytics.Worker.Services;
@@ -33,6 +34,10 @@ public class DiscoveryWorker : BackgroundService
// Run discovery for all implemented platforms
foreach (var platform in new[] { PlatformType.Polymarket, PlatformType.Limitless })
{
var config = scope.ServiceProvider.GetRequiredService<Microsoft.Extensions.Configuration.IConfiguration>();
bool isEnabled = config.GetValue<bool>($"PlatformSettings:{platform}:EnableCrawling", platform == PlatformType.Polymarket);
if (!isEnabled) continue;
try
{
if (stoppingToken.IsCancellationRequested) break;
@@ -5,6 +5,7 @@ using Predictalytics.Infrastructure.Logging;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
namespace Predictalytics.Worker.Services;
@@ -37,6 +38,10 @@ public class MarketSyncWorker : BackgroundService
foreach (var p in platformProviders.Where(x => x.IsImplemented))
{
var config = _services.GetRequiredService<Microsoft.Extensions.Configuration.IConfiguration>();
bool isEnabled = config.GetValue<bool>($"PlatformSettings:{p.PlatformName}:EnableCrawling", p.Platform == PlatformType.Polymarket);
if (!isEnabled) continue;
try
{
if (stoppingToken.IsCancellationRequested) break;
@@ -53,8 +53,8 @@ public class ReportingWorker : BackgroundService
foreach (var (platform, stats) in statsMap)
{
var dupStr = stats.DuplicateErrors > 0 ? $" | Duplikatfehler: {stats.DuplicateErrors}" : "";
_logger.LogWarning("[{Platform}] Markets: {M} | New Traders: {T} | Activities: {A}{D}",
platform, stats.MarketsSynced, stats.TradersDiscovered, stats.TradesProcessed, dupStr);
_logger.LogWarning("[{Platform}] Markets: {M} | New Traders: {T} | Analyzed: {An} | Activities: {A}{D}",
platform, stats.MarketsSynced, stats.TradersDiscovered, stats.TradersAnalyzed, stats.TradesProcessed, dupStr);
}
_logger.LogWarning("------------------------------------------------");
@@ -5,6 +5,7 @@ using Predictalytics.Infrastructure.Logging;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
namespace Predictalytics.Worker.Services;
@@ -96,6 +97,15 @@ public class TradeHistoryWorker : BackgroundService
var provider = providers.FirstOrDefault(p => p.Platform == trader.Platform && p.IsImplemented);
if (provider == null) return;
var config = scope.ServiceProvider.GetRequiredService<Microsoft.Extensions.Configuration.IConfiguration>();
bool isEnabled = config.GetValue<bool>($"PlatformSettings:{provider.PlatformName}:EnableCrawling", provider.Platform == PlatformType.Polymarket);
if (!isEnabled)
{
trader.LastPolledAt = DateTime.UtcNow;
await traderRepo.UpdateAsync(trader, ct);
return;
}
using var platformCtx = PlatformLogContext.Push(provider.PlatformName);
await rateLimiter.WaitAsync(trader.Platform, ct);
@@ -110,6 +110,12 @@ public class TraderAnalyticsWorker : BackgroundService
}
trader.LastAnalyzedAt = DateTime.UtcNow;
await traderRepo.UpdateAsync(trader, ct);
var statsService = traderScope.ServiceProvider.GetService<IPlatformStatisticsService>();
if (statsService != null)
{
statsService.TrackTradersAnalyzed(trader.Platform, 1);
}
}
if (activeJob != null && activeJob.TraderId == id)