Phase 3: Trading-Kern (Risk, Execution, Portfolio) mit sicherem Broker-Default - Core/Trading/TradingModels: Signal, Order(Request/Result), RiskContext/Decision, Account, Position, Quote, ExecutionResult, Enums (Side/OrderType/Mode) - IBrokerClient + NullBrokerClient (sicherer Default, handelt NIE bis IBKR-Adapter verifiziert) - RiskService (+IRiskService): Sizing nach MaxTrade%, Modul-Limit, Slippage; Buy/Sell - PortfolioService (+IPortfolioService): core_position + core_trade_history + core_budget - ExecutionService (+IExecutionService): Signal -> Kurs -> Konto -> Risiko -> Order -> Buchung - TradingSettings in AppSettings (Paper/Live, TradingEnabled, Risikoparameter) - CoreMigrations: core_position; DI-Registrierung der Trading-Services - Tests: RiskService (11) + ExecutionService (6, NSubstitute) -> 38/38 gruen Offen (bewusst gekapselt): echter IbkrBrokerClient gegen Client-Portal-Gateway (manuell verifizieren). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> @
110 lines
4.2 KiB
C#
110 lines
4.2 KiB
C#
using IBKRTrader.Core.AI;
|
|
using IBKRTrader.Core.Budget;
|
|
using IBKRTrader.Core.Database;
|
|
using IBKRTrader.Core.Database.Migrations;
|
|
using IBKRTrader.Core.IBKR;
|
|
using IBKRTrader.Core.Logging;
|
|
using IBKRTrader.Core.Modules;
|
|
using IBKRTrader.Core.Settings;
|
|
using IBKRTrader.Core.Trading;
|
|
using IBKRTrader.Core.Workers;
|
|
using IBKRTrader.Core.Workers.BuiltIn;
|
|
using IBKRTrader.Modules.CongressTrading;
|
|
using IBKRTrader.UI;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace IBKRTrader;
|
|
|
|
internal static class Program
|
|
{
|
|
[STAThread]
|
|
static void Main()
|
|
{
|
|
ApplicationConfiguration.Initialize();
|
|
|
|
// ── DI-Container aufbauen ────────────────────────────────────────────
|
|
var services = new ServiceCollection();
|
|
|
|
// Core: Settings (zuerst laden)
|
|
var settingsService = new SettingsService();
|
|
settingsService.Load();
|
|
services.AddSingleton(settingsService);
|
|
|
|
// Core: Logging
|
|
services.AddSingleton<LoggingService>();
|
|
|
|
// Core: Database
|
|
services.AddSingleton<DatabaseService>();
|
|
services.AddSingleton<CoreMigrations>();
|
|
services.AddSingleton<IBKRMigrations>();
|
|
|
|
// Core: IBKR Services
|
|
services.AddSingleton<IBKRGatewayService>();
|
|
services.AddSingleton<IBKRMarketDataRepository>();
|
|
|
|
// Core: Other Services
|
|
services.AddSingleton<BudgetService>();
|
|
services.AddSingleton<TradeHistoryService>();
|
|
services.AddSingleton<AIModelService>();
|
|
|
|
// Core: Trading-Kern
|
|
services.AddSingleton<IRiskService, RiskService>();
|
|
services.AddSingleton<IPortfolioService, PortfolioService>();
|
|
services.AddSingleton<IExecutionService, ExecutionService>();
|
|
// Sicherer Standard-Broker: handelt nicht, bis der echte IBKR-Adapter
|
|
// angebunden und gegen den Paper-Gateway verifiziert ist.
|
|
services.AddSingleton<IBrokerClient, NullBrokerClient>();
|
|
|
|
// Core: Built-In Worker
|
|
services.AddSingleton<BackupWorker>();
|
|
services.AddSingleton<WebserverService>();
|
|
services.AddSingleton<WebApiService>();
|
|
services.AddSingleton<IBKRInstrumentSyncWorker>();
|
|
services.AddSingleton<IBKRPriceHistoryWorker>();
|
|
|
|
// ── Module registrieren ──────────────────────────────────────────────
|
|
// Der Core kennt konkrete Module nicht: Module werden hier instanziiert,
|
|
// hängen ihre Services über IModule.RegisterServices ein und werden über
|
|
// die ModuleRegistry zugänglich gemacht.
|
|
IModule[] modules =
|
|
[
|
|
new CongressTradingModule(),
|
|
];
|
|
|
|
foreach (var module in modules)
|
|
module.RegisterServices(services);
|
|
|
|
var moduleRegistry = new ModuleRegistry(modules);
|
|
services.AddSingleton(moduleRegistry);
|
|
|
|
// ── IWorker-Sammlung: Core + Module ──────────────────────────────────
|
|
services.AddSingleton<IEnumerable<IWorker>>(sp => new IWorker[]
|
|
{
|
|
// Core-Worker
|
|
sp.GetRequiredService<BackupWorker>(),
|
|
sp.GetRequiredService<WebserverService>(),
|
|
sp.GetRequiredService<WebApiService>(),
|
|
// IBKR Market Data Worker
|
|
sp.GetRequiredService<IBKRInstrumentSyncWorker>(),
|
|
sp.GetRequiredService<IBKRPriceHistoryWorker>(),
|
|
}
|
|
// Modul-Worker dynamisch anhängen
|
|
.Concat(moduleRegistry.Modules.SelectMany(m => m.GetWorkers(sp)))
|
|
.ToArray());
|
|
|
|
services.AddSingleton<WorkerEngine>();
|
|
|
|
// UI: Launcher + Fenster-Verwaltung
|
|
services.AddSingleton<WindowManager>();
|
|
services.AddSingleton<LauncherForm>();
|
|
|
|
var provider = services.BuildServiceProvider();
|
|
|
|
// WebApiService bekommt Engine-Referenz (zirkuläre Abhängigkeit auflösen)
|
|
var webApi = provider.GetRequiredService<WebApiService>();
|
|
var engine = provider.GetRequiredService<WorkerEngine>();
|
|
webApi.SetEngine(engine);
|
|
|
|
Application.Run(provider.GetRequiredService<LauncherForm>());
|
|
}
|
|
} |