using Managing.Application.Abstractions; using Managing.Application.Abstractions.Repositories; using Managing.Application.Abstractions.Services; using Managing.Application.Accounts; using Managing.Application.Backtests; using Managing.Application.MoneyManagements; using Managing.Application.Scenarios; using Managing.Application.Shared; using Managing.Application.Synth; using Managing.Application.Trading; using Managing.Application.Users; using Managing.Application.Whitelist; using Managing.Domain.Statistics; using Managing.Domain.Trades; using Managing.Infrastructure.Databases; using Managing.Infrastructure.Databases.InfluxDb; using Managing.Infrastructure.Databases.InfluxDb.Abstractions; using Managing.Infrastructure.Databases.InfluxDb.Models; using Managing.Infrastructure.Databases.PostgreSql; using Managing.Infrastructure.Databases.PostgreSql.Configurations; using Managing.Infrastructure.Evm; using Managing.Infrastructure.Evm.Services; using Managing.Infrastructure.Evm.Subgraphs; using Managing.Infrastructure.Exchanges; using Managing.Infrastructure.Exchanges.Abstractions; using Managing.Infrastructure.Exchanges.Exchanges; using Managing.Infrastructure.Storage; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using static Managing.Common.Enums; namespace Managing.Bootstrap; /// /// Bootstrap configuration for compute worker project (no Orleans) /// public static class ComputeBootstrap { public static IServiceCollection RegisterComputeDependencies(this IServiceCollection services, IConfiguration configuration) { return services .AddApplication() .AddInfrastructure(configuration); } private static IServiceCollection AddApplication(this IServiceCollection services) { // Core services needed for backtest execution services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); // Services not needed for compute worker (depend on IBacktester/Orleans) // services.AddScoped(); // Requires IBacktester // services.AddScoped(); // Requires IBacktester // services.AddScoped(); // Requires IBacktester // services.AddScoped(); // May require Orleans // services.AddScoped(); // May require Orleans // services.AddScoped(); // May require Orleans // services.AddScoped(); // May require Orleans // Processors // Note: IBacktester not needed for compute worker - BacktestExecutor is used directly services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); // Web3Proxy service (needed for EvmManager) services.AddTransient(); // Evm services (needed for ExchangeService) services.AddGbcFeed(); services.AddUniswapV2(); services.AddChainlink(); services.AddChainlinkGmx(); services.AddSingleton(); services.AddTransient(); services.AddTransient(); // Synth services (needed for TradingService) services.AddScoped(); services.AddScoped(); // No-op implementations for compute worker (no Discord needed) services.AddSingleton(); // IGrainFactory is optional in UserService - register as null for compute workers services.AddSingleton(sp => null!); // Webhook service (required for notifications) services.AddHttpClient(); // MessengerService must be Scoped because it depends on IUserService which is Scoped services.AddScoped(); return services; } private static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration) { // Database services.AddSingleton(sp => sp.GetRequiredService>().Value); services.AddSingleton(sp => sp.GetRequiredService>().Value); services.Configure(configuration.GetSection("Kaigen")); services.Configure(configuration.GetSection("Web3Proxy")); // SQL Monitoring (required by repositories) services.Configure(configuration.GetSection("SqlMonitoring")); services.AddSingleton(); // PostgreSql Repositories services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); // InfluxDb Repositories services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); // Cache services.AddDistributedMemoryCache(); services.AddTransient(); services.AddSingleton(); return services; } } /// /// No-op implementation of IDiscordService for compute workers /// internal class NoOpDiscordService : IDiscordService { public Task SendSignal(string message, TradingExchanges exchange, Ticker ticker, TradeDirection direction, Timeframe timeframe) => Task.CompletedTask; public Task SendPosition(Position position) => Task.CompletedTask; public Task SendClosingPosition(Position position) => Task.CompletedTask; public Task SendMessage(string v) => Task.CompletedTask; public Task SendTradeMessage(string message, bool isBadBehavior = false) => Task.CompletedTask; public Task SendIncreasePosition(string address, Trade trade, string copyAccountName, Trade? oldTrade = null) => Task.CompletedTask; public Task SendClosedPosition(string address, Trade oldTrade) => Task.CompletedTask; public Task SendDecreasePosition(string address, Trade newTrade, decimal decreaseAmount) => Task.CompletedTask; public Task SendBestTraders(List traders) => Task.CompletedTask; public Task SendBadTraders(List traders) => Task.CompletedTask; public Task SendDowngradedFundingRate(FundingRate oldRate) => Task.CompletedTask; public Task SendNewTopFundingRate(FundingRate newRate) => Task.CompletedTask; public Task SendFundingRateUpdate(FundingRate oldRate, FundingRate newRate) => Task.CompletedTask; public Task SendDebugMessage(string message) => Task.CompletedTask; }