65 lines
2.4 KiB
C#
65 lines
2.4 KiB
C#
using System;
|
|
using FinlyticAnalyzer.Database;
|
|
using FinlyticAnalyzer.Services;
|
|
using FinlyticAnalyzer.Util;
|
|
using FinlyticCore.Database;
|
|
using FinlyticCore.Services;
|
|
using FinlyticCore.Services.Yahoo;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
var builder = Host.CreateApplicationBuilder(args);
|
|
|
|
// Register DB Context
|
|
builder.Services.AddDbContext<AnalyzerDbContext>(options =>
|
|
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
|
|
builder.Services.AddScoped<ISettingsDbContext>(sp => sp.GetRequiredService<AnalyzerDbContext>());
|
|
|
|
// Register Core Services
|
|
builder.Services.AddSingleton<ISettingsService, SettingsService>();
|
|
builder.Services.AddSingleton(typeof(IFinlyticLogger<>), typeof(FinlyticLogger<>));
|
|
|
|
// Register HTTP Clients for external webhooks (HttpClientFactory manages pool)
|
|
builder.Services.AddHttpClient<IN8nEvaluationService, N8nEvaluationService>();
|
|
|
|
// Register Domain Services
|
|
builder.Services.AddSingleton<IVixTrackerService, VixTrackerService>();
|
|
builder.Services.AddSingleton<IThreeLayerFilterEngine, ThreeLayerFilterEngine>();
|
|
builder.Services.AddSingleton<IWinRateCalculator, WinRateCalculator>();
|
|
builder.Services.AddScoped<ISettingsDbService, SettingsDbService>();
|
|
builder.Services.AddSingleton<YahooFinanceClient>();
|
|
|
|
// Unified MQTT Client (Handles both Events and RPC)
|
|
builder.Services.AddSingleton<AnalyzerMqttClient>();
|
|
builder.Services.AddHostedService(provider => provider.GetRequiredService<AnalyzerMqttClient>());
|
|
|
|
// Register Active Trade Monitor
|
|
builder.Services.AddHostedService<ActiveTradeMonitorWorker>();
|
|
|
|
var host = builder.Build();
|
|
|
|
// Run DB Migrations
|
|
using (var scope = host.Services.CreateScope())
|
|
{
|
|
try
|
|
{
|
|
var context = scope.ServiceProvider.GetRequiredService<AnalyzerDbContext>();
|
|
await context.Database.MigrateAsync();
|
|
Console.WriteLine("Database migrations successfully executed for FinlyticAnalyzer.");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Critical error during database migration for FinlyticAnalyzer: {ex.Message}");
|
|
}
|
|
}
|
|
|
|
// Initial VIX Poll
|
|
using (var scope = host.Services.CreateScope())
|
|
{
|
|
var vixService = scope.ServiceProvider.GetRequiredService<IVixTrackerService>();
|
|
await vixService.PollVixAsync();
|
|
}
|
|
|
|
await host.RunAsync(); |