Files
IBKRTrader/Core/Trading/TradeHistoryService.cs
T
RichardandClaude Opus 4.8 ebeb035e92 Initial commit: IBKRTrader
.NET WinForms-Anwendung (Core, Modules/CongressTrading, UI).
Enthaelt .gitignore und settings.example.json als Konfigurationsvorlage.
Echte settings.json mit Zugangsdaten ist bewusst ausgeschlossen.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-26 18:19:47 +02:00

48 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using IBKRTrader.Core.Database;
using IBKRTrader.Core.Logging;
namespace IBKRTrader.Core.Trading;
/// <summary>Verwaltet core_trade_history Lesen und Schreiben von Trade-Einträgen.</summary>
public class TradeHistoryService
{
private readonly DatabaseService _db;
private readonly LoggingService _logger;
public TradeHistoryService(DatabaseService db, LoggingService logger)
{
_db = db;
_logger = logger;
}
public async Task RecordTradeAsync(
string module, string symbol, string action,
decimal quantity, decimal price, string? ibkrOrderId = null, string? notes = null)
{
await _db.ExecuteAsync(@"
INSERT INTO `core_trade_history`
(module, symbol, action, quantity, price, total_value, traded_at, ibkr_order_id, status, notes)
VALUES
(@module, @symbol, @action, @qty, @price, @total, @now, @orderId, 'Executed', @notes)",
new
{
module,
symbol,
action,
qty = quantity,
price,
total = quantity * price,
now = DateTime.UtcNow,
orderId = ibkrOrderId,
notes
});
_logger.Info(module, $"Trade gespeichert: {action} {quantity}x {symbol} @ {price:F2}");
}
public async Task<IEnumerable<dynamic>> GetRecentTradesAsync(int limit = 100)
=> await _db.QueryAsync<dynamic>(
"SELECT * FROM `core_trade_history` ORDER BY traded_at DESC LIMIT @limit",
new { limit });
}