@
R7: Dashboard-View + DashboardService (Abschluss Feinschliff) - Core/Trading/DashboardService: aggregiert Positionen/Exposure/Trades via EF (DashboardSnapshot) - UI/Views/DashboardView: Trading-Modus, aggregierte Kennzahlen, geladene Module (+ Aktivierungs-Status) - core.dashboard-View registriert (Order 5) mit dashboard-Icon - Tests: DashboardService (leer + Aggregation, InMemory) -> 58/58 gruen; smoke-ui deckt alle 5 Views ab Kurskorrektur R1-R7 abgeschlossen: IBKRTrader folgt dem PolytraderSharp-Konzept. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> @
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
using IBKRTrader.Core.Persistence.Ef;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace IBKRTrader.Core.Trading;
|
||||
|
||||
/// <summary>Aggregierte Kennzahlen über alle Module für das Dashboard.</summary>
|
||||
public sealed record DashboardSnapshot(int OpenPositions, decimal TotalExposure, int TotalTrades);
|
||||
|
||||
/// <summary>Liest aggregierte Portfolio-Kennzahlen (EF Core) für die Dashboard-Ansicht.</summary>
|
||||
public sealed class DashboardService
|
||||
{
|
||||
private readonly IDbContextFactory<CoreDbContext> _dbf;
|
||||
|
||||
public DashboardService(IDbContextFactory<CoreDbContext> dbf) => _dbf = dbf;
|
||||
|
||||
public async Task<DashboardSnapshot> GetSnapshotAsync(CancellationToken ct = default)
|
||||
{
|
||||
await using var db = await _dbf.CreateDbContextAsync(ct);
|
||||
var positions = await db.Positions.ToListAsync(ct);
|
||||
var trades = await db.TradeHistory.CountAsync(ct);
|
||||
return new DashboardSnapshot(
|
||||
OpenPositions: positions.Count,
|
||||
TotalExposure: positions.Sum(p => p.Quantity * p.AvgPrice),
|
||||
TotalTrades: trades);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user