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>
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
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 });
|
||||
}
|
||||
Reference in New Issue
Block a user