Implement WinRate, Bankroll, Positions UI and add Trades30d to Analytics

This commit is contained in:
Richard
2026-07-09 12:44:32 +02:00
parent 3b11b71188
commit 7964194e9e
16 changed files with 1318 additions and 28 deletions
@@ -155,4 +155,14 @@ public class TraderRepository : ITraderRepository
.Take(take)
.ToListAsync(ct);
}
public async Task<IReadOnlyList<TraderPosition>> GetPositionsAsync(int traderId, CancellationToken ct = default)
{
return await _db.TraderPositions
.Include(p => p.MarketOutcome)
.ThenInclude(o => o.Market)
.Where(p => p.TraderId == traderId && (p.SharesHeld > 0 || p.RealizedPnl != 0))
.OrderByDescending(p => p.LastTradeExecutedAt ?? DateTime.MinValue)
.ToListAsync(ct);
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Predictalytics.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class AddTrades30dToAnalytics : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "Trades30d",
table: "TraderAnalytics",
type: "int",
nullable: false,
defaultValue: 0);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Trades30d",
table: "TraderAnalytics");
}
}
}
@@ -667,6 +667,9 @@ namespace Predictalytics.Infrastructure.Migrations
.HasPrecision(18, 4)
.HasColumnType("decimal(18,4)");
b.Property<int>("Trades30d")
.HasColumnType("int");
b.Property<decimal>("WinRate24h")
.HasPrecision(8, 4)
.HasColumnType("decimal(8,4)");
@@ -321,6 +321,9 @@ public class PositionPnLEngine : IPositionPnLEngine
analytics.PnL7d = overallPnl - (snapshot7d?.TotalPnl ?? 0);
analytics.PnL30d = overallPnl - (snapshot30d?.TotalPnl ?? 0);
// Count Trades30d
analytics.Trades30d = trades.Count(t => t.ExecutedAt >= cutoff30d);
// Calculate Win Rate on Market level
var (winRateOverall, winRate30d, winRate7d, winRate24h) = CalculateMarketWinRates(trades, tempPositions, cutoff30d, cutoff7d, cutoff24h);