Trading bot grain (#33)

* Trading bot Grain

* Fix a bit more of the trading bot

* Advance on the tradingbot grain

* Fix build

* Fix db script

* Fix user login

* Fix a bit backtest

* Fix cooldown and backtest

* start fixing bot start

* Fix startup

* Setup local db

* Fix build and update candles and scenario

* Add bot registry

* Add reminder

* Updateing the grains

* fix bootstraping

* Save stats on tick

* Save bot data every tick

* Fix serialization

* fix save bot stats

* Fix get candles

* use dict instead of list for position

* Switch hashset to dict

* Fix a bit

* Fix bot launch and bot view

* add migrations

* Remove the tolist

* Add agent grain

* Save agent summary

* clean

* Add save bot

* Update get bots

* Add get bots

* Fix stop/restart

* fix Update config

* Update scanner table on new backtest saved

* Fix backtestRowDetails.tsx

* Fix agentIndex

* Update agentIndex

* Fix more things

* Update user cache

* Fix

* Fix account load/start/restart/run
This commit is contained in:
Oda
2025-08-04 23:07:06 +02:00
committed by GitHub
parent cd378587aa
commit 082ae8714b
215 changed files with 9562 additions and 14028 deletions

View File

@@ -8,7 +8,6 @@ using Managing.Application.Abstractions.Repositories;
using Managing.Application.Abstractions.Services;
using Managing.Application.Accounts;
using Managing.Application.Backtesting;
using Managing.Application.Bots.Base;
using Managing.Application.ManageBot;
using Managing.Application.ManageBot.Commands;
using Managing.Application.MoneyManagements;
@@ -22,6 +21,7 @@ using Managing.Application.Users;
using Managing.Application.Workers;
using Managing.Application.Workers.Abstractions;
using Managing.Domain.Trades;
using Managing.Infrastructure.Database.PostgreSql;
using Managing.Infrastructure.Databases;
using Managing.Infrastructure.Databases.InfluxDb;
using Managing.Infrastructure.Databases.InfluxDb.Abstractions;
@@ -74,31 +74,43 @@ public static class ApiBootstrap
public static IHostBuilder ConfigureOrleans(this IHostBuilder hostBuilder, IConfiguration configuration,
bool isProduction)
{
var postgreSqlConnectionString = configuration.GetSection("Databases:PostgreSql")["ConnectionString"];
var postgreSqlConnectionString = configuration.GetSection("PostgreSql")["Orleans"];
return hostBuilder.UseOrleans(siloBuilder =>
{
// Configure clustering
if (isProduction && !string.IsNullOrEmpty(postgreSqlConnectionString))
{
// Production clustering configuration
siloBuilder
.UseAdoNetClustering(options =>
{
options.ConnectionString = postgreSqlConnectionString;
options.Invariant = "Npgsql";
})
.UseAdoNetReminderService(options =>
{
options.ConnectionString = postgreSqlConnectionString;
options.Invariant = "Npgsql";
});
}
else
{
// Development clustering configuration
siloBuilder.UseLocalhostClustering();
}
// Configure clustering with improved networking
siloBuilder
.UseAdoNetClustering(options =>
{
options.ConnectionString = postgreSqlConnectionString;
options.Invariant = "Npgsql";
})
.UseAdoNetReminderService(options =>
{
options.ConnectionString = postgreSqlConnectionString;
options.Invariant = "Npgsql";
});
// Configure networking for better silo communication
siloBuilder
.ConfigureEndpoints(siloPort: 11111, gatewayPort: 30000)
.Configure<ClusterOptions>(options =>
{
// Configure cluster options with unique identifiers
options.ServiceId = "ManagingApp";
options.ClusterId = configuration["ASPNETCORE_ENVIRONMENT"] ?? "Development";
})
.Configure<GrainCollectionOptions>(options =>
{
// Configure grain collection to prevent memory issues
options.CollectionAge = TimeSpan.FromMinutes(10);
options.CollectionQuantum = TimeSpan.FromMinutes(1);
})
.Configure<MessagingOptions>(options =>
{
// Configure messaging for better reliability
options.ResponseTimeout = TimeSpan.FromSeconds(30);
});
siloBuilder
.ConfigureLogging(logging => logging.SetMinimumLevel(LogLevel.Information));
@@ -113,10 +125,28 @@ public static class ApiBootstrap
options.HostSelf = true;
options.CounterUpdateIntervalMs = 10000; // 10 seconds
options.HideTrace = true; // Hide trace to reduce dashboard overhead
options.Host = "0.0.0.0"; // Allow external connections
options.Username = "admin";
options.Password = "admin";
});
}
siloBuilder.AddMemoryGrainStorageAsDefault()
siloBuilder
.AddAdoNetGrainStorage("bot-store", options =>
{
options.ConnectionString = postgreSqlConnectionString;
options.Invariant = "Npgsql";
})
.AddAdoNetGrainStorage("registry-store", options =>
{
options.ConnectionString = postgreSqlConnectionString;
options.Invariant = "Npgsql";
})
.AddAdoNetGrainStorage("agent-store", options =>
{
options.ConnectionString = postgreSqlConnectionString;
options.Invariant = "Npgsql";
})
.ConfigureServices(services =>
{
// Register existing services for Orleans DI
@@ -125,13 +155,6 @@ public static class ApiBootstrap
services.AddTransient<IAccountService, AccountService>();
services.AddTransient<ITradingService, TradingService>();
services.AddTransient<IMessengerService, MessengerService>();
services.AddTransient<IBackupBotService, BackupBotService>();
})
.Configure<ClusterOptions>(options =>
{
// Configure cluster options
options.ServiceId = "ManagingApp";
options.ClusterId = configuration["ASPNETCORE_ENVIRONMENT"] ?? "Development";
});
})
;
@@ -148,7 +171,6 @@ public static class ApiBootstrap
services.AddScoped<ISettingsService, SettingsService>();
services.AddScoped<IUserService, UserService>();
services.AddScoped<IGeneticService, GeneticService>();
services.AddScoped<IBackupBotService, BackupBotService>();
services.AddSingleton<IBotService, BotService>();
services.AddScoped<IWorkerService, WorkerService>();
services.AddScoped<ISynthPredictionService, SynthPredictionService>();
@@ -170,7 +192,6 @@ public static class ApiBootstrap
services.AddTransient<IWebhookService, WebhookService>();
services.AddTransient<IKaigenService, KaigenService>();
services.AddSingleton<IBotFactory, BotFactory>();
services.AddSingleton<IMessengerService, MessengerService>();
services.AddSingleton<IDiscordService, DiscordService>();
@@ -206,6 +227,7 @@ public static class ApiBootstrap
services.AddTransient<ITradingRepository, PostgreSqlTradingRepository>();
services.AddTransient<ISettingsRepository, PostgreSqlSettingsRepository>();
services.AddTransient<IUserRepository, PostgreSqlUserRepository>();
services.AddTransient<IAgentSummaryRepository, AgentSummaryRepository>();
services.AddTransient<IStatisticRepository, PostgreSqlStatisticRepository>();
services.AddTransient<IBotRepository, PostgreSqlBotRepository>();
services.AddTransient<IWorkerRepository, PostgreSqlWorkerRepository>();
@@ -230,11 +252,6 @@ public static class ApiBootstrap
private static IServiceCollection AddWorkers(this IServiceCollection services, IConfiguration configuration)
{
if (configuration.GetValue<bool>("WorkerBotManager", false))
{
services.AddHostedService<BotManagerWorker>();
}
if (configuration.GetValue<bool>("WorkerBalancesTracking", false))
{
services.AddHostedService<BalanceTrackingWorker>();