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
@@ -16,6 +16,7 @@ public class AppDbContext : DbContext
public DbSet<TraderAnalytics> TraderAnalytics => Set<TraderAnalytics>();
public DbSet<MarketAnalytics> MarketAnalytics => Set<MarketAnalytics>();
public DbSet<TraderPosition> TraderPositions => Set<TraderPosition>();
public DbSet<MarketOutcomePriceSnapshot> MarketOutcomePriceSnapshots => Set<MarketOutcomePriceSnapshot>();
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
@@ -103,6 +104,7 @@ public class AppDbContext : DbContext
e.Property(s => s.CombinedScore).HasPrecision(8, 4);
e.Property(s => s.VolumeScore).HasPrecision(8, 4);
e.Property(s => s.TimingScore).HasPrecision(8, 4);
e.Property(s => s.CopytradingScore).HasPrecision(8, 4);
});
// WatchlistEntry
@@ -166,5 +168,14 @@ public class AppDbContext : DbContext
e.HasOne(tp => tp.Trader).WithMany(t => t.Positions).HasForeignKey(tp => tp.TraderId).OnDelete(DeleteBehavior.Cascade);
e.HasOne(tp => tp.MarketOutcome).WithMany().HasForeignKey(tp => tp.MarketOutcomeId).OnDelete(DeleteBehavior.Cascade);
});
// MarketOutcomePriceSnapshot
mb.Entity<MarketOutcomePriceSnapshot>(e =>
{
e.HasKey(ps => ps.Id);
e.HasIndex(ps => new { ps.MarketOutcomeId, ps.Timestamp });
e.Property(ps => ps.Price).HasPrecision(10, 6);
e.HasOne(ps => ps.MarketOutcome).WithMany().HasForeignKey(ps => ps.MarketOutcomeId).OnDelete(DeleteBehavior.Cascade);
});
}
}
@@ -198,4 +198,23 @@ public class MarketRepository : IMarketRepository
.Take(take)
.ToListAsync(ct);
}
public async Task<IReadOnlyList<MarketOutcomePriceSnapshot>> GetPriceSnapshotsAsync(int marketOutcomeId, CancellationToken ct = default)
{
return await _db.MarketOutcomePriceSnapshots
.Where(ps => ps.MarketOutcomeId == marketOutcomeId)
.OrderBy(ps => ps.Timestamp)
.ToListAsync(ct);
}
public async Task SavePriceSnapshotsAsync(int marketOutcomeId, IEnumerable<MarketOutcomePriceSnapshot> snapshots, CancellationToken ct = default)
{
var existing = await _db.MarketOutcomePriceSnapshots
.Where(ps => ps.MarketOutcomeId == marketOutcomeId)
.ToListAsync(ct);
_db.MarketOutcomePriceSnapshots.RemoveRange(existing);
_db.MarketOutcomePriceSnapshots.AddRange(snapshots);
await _db.SaveChangesAsync(ct);
}
}