Postgres (#30)

* Add postgres

* Migrate users

* Migrate geneticRequest

* Try to fix Concurrent call

* Fix asyncawait

* Fix async and concurrent

* Migrate backtests

* Add cache for user by address

* Fix backtest migration

* Fix not open connection

* Fix backtest command error

* Fix concurrent

* Fix all concurrency

* Migrate TradingRepo

* Fix scenarios

* Migrate statistic repo

* Save botbackup

* Add settings et moneymanagement

* Add bot postgres

* fix a bit more backups

* Fix bot model

* Fix loading backup

* Remove cache market for read positions

* Add workers to postgre

* Fix workers api

* Reduce get Accounts for workers

* Migrate synth to postgre

* Fix backtest saved

* Remove mongodb

* botservice decorrelation

* Fix tradingbot scope call

* fix tradingbot

* fix concurrent

* Fix scope for genetics

* Fix account over requesting

* Fix bundle backtest worker

* fix a lot of things

* fix tab backtest

* Remove optimized moneymanagement

* Add light signal to not use User and too much property

* Make money management lighter

* insert indicators to awaitable

* Migrate add strategies to await

* Refactor scenario and indicator retrieval to use asynchronous methods throughout the application

* add more async await

* Add services

* Fix and clean

* Fix bot a bit

* Fix bot and add message for cooldown

* Remove fees

* Add script to deploy db

* Update dfeeploy script

* fix script

* Add idempotent script and backup

* finish script migration

* Fix did user and agent name on start bot
This commit is contained in:
Oda
2025-07-27 15:42:17 +02:00
committed by GitHub
parent 361bfbf6e8
commit 422fecea7b
294 changed files with 23953 additions and 7272 deletions

View File

@@ -32,18 +32,7 @@ public class SettingsService : ISettingsService
throw new Exception("Cannot delete all backtests");
}
if (!_scenarioService.DeleteScenarios())
{
throw new Exception("Cannot delete scenarios");
}
if (!_scenarioService.DeleteStrategies())
{
throw new Exception("Cannot delete all strategies");
}
if (!SetupSettings())
if (!await SetupSettings())
{
throw new Exception("Cannot setup settings");
}
@@ -51,7 +40,7 @@ public class SettingsService : ISettingsService
return await Task.FromResult(true);
}
public bool SetupSettings()
public async Task<bool> SetupSettings()
{
try
{
@@ -59,7 +48,7 @@ public class SettingsService : ISettingsService
// SetupMoneyManagementsSeed(Timeframe.FifteenMinutes);
// SetupMoneyManagementsSeed(Timeframe.OneHour);
// SetupMoneyManagementsSeed(Timeframe.OneDay);
SetupScenariosSeed();
await SetupScenariosSeed();
}
catch (Exception ex)
{
@@ -85,107 +74,107 @@ public class SettingsService : ISettingsService
// await _moneyManagementService.CreateOrUpdateMoneyManagement(moneyManagement);
// }
private void SetupScenariosSeed()
private async Task SetupScenariosSeed()
{
SetupMacd();
SetupRsiDiv();
SetupRsiDivConfirm();
SetupSuperTrend();
SetupChandelierExit();
SetupStochRsiTrend();
SetupStochSTCTrend();
SetupEmaTrend();
SetupEmaCross();
await SetupMacd();
await SetupRsiDiv();
await SetupRsiDivConfirm();
await SetupSuperTrend();
await SetupChandelierExit();
await SetupStochRsiTrend();
await SetupStochSTCTrend();
await SetupEmaTrend();
await SetupEmaCross();
}
private void SetupStochSTCTrend()
private async Task SetupStochSTCTrend()
{
var name = "STCTrend";
var strategy = _scenarioService.CreateStrategy(IndicatorType.Stc,
var strategy = await _scenarioService.CreateStrategy(IndicatorType.Stc,
name,
fastPeriods: 23,
slowPeriods: 50,
cyclePeriods: 10);
_scenarioService.CreateScenario(name, new List<string> { strategy.Name });
await _scenarioService.CreateScenario(name, new List<string> { strategy.Name });
}
private void SetupMacd()
private async Task SetupMacd()
{
var name = "MacdCross";
var strategy = _scenarioService.CreateStrategy(IndicatorType.MacdCross,
var strategy = await _scenarioService.CreateStrategy(IndicatorType.MacdCross,
name,
fastPeriods: 12,
slowPeriods: 26,
signalPeriods: 9);
_scenarioService.CreateScenario(name, new List<string> { strategy.Name });
await _scenarioService.CreateScenario(name, new List<string> { strategy.Name });
}
private void SetupRsiDiv()
private async Task SetupRsiDiv()
{
var name = "RsiDiv6";
var strategy = _scenarioService.CreateStrategy(IndicatorType.RsiDivergence,
var strategy = await _scenarioService.CreateStrategy(IndicatorType.RsiDivergence,
name,
period: 6);
_scenarioService.CreateScenario(name, new List<string> { strategy.Name });
await _scenarioService.CreateScenario(name, new List<string> { strategy.Name });
}
private void SetupRsiDivConfirm()
private async Task SetupRsiDivConfirm()
{
var name = "RsiDivConfirm6";
var strategy = _scenarioService.CreateStrategy(IndicatorType.RsiDivergenceConfirm,
var strategy = await _scenarioService.CreateStrategy(IndicatorType.RsiDivergenceConfirm,
name,
period: 6);
_scenarioService.CreateScenario(name, new List<string> { strategy.Name });
await _scenarioService.CreateScenario(name, new List<string> { strategy.Name });
}
private void SetupSuperTrend()
private async Task SetupSuperTrend()
{
var name = "SuperTrend";
var strategy = _scenarioService.CreateStrategy(IndicatorType.SuperTrend,
var strategy = await _scenarioService.CreateStrategy(IndicatorType.SuperTrend,
name,
period: 10,
multiplier: 3);
_scenarioService.CreateScenario(name, new List<string> { strategy.Name });
await _scenarioService.CreateScenario(name, new List<string> { strategy.Name });
}
private void SetupChandelierExit()
private async Task SetupChandelierExit()
{
var name = "ChandelierExit";
var strategy = _scenarioService.CreateStrategy(IndicatorType.ChandelierExit,
var strategy = await _scenarioService.CreateStrategy(IndicatorType.ChandelierExit,
name,
period: 22,
multiplier: 3);
_scenarioService.CreateScenario(name, new List<string> { strategy.Name });
await _scenarioService.CreateScenario(name, new List<string> { strategy.Name });
}
private void SetupStochRsiTrend()
private async Task SetupStochRsiTrend()
{
var name = "StochRsiTrend";
var strategy = _scenarioService.CreateStrategy(IndicatorType.StochRsiTrend,
var strategy = await _scenarioService.CreateStrategy(IndicatorType.StochRsiTrend,
name,
period: 14,
stochPeriods: 14,
signalPeriods: 3,
smoothPeriods: 1);
_scenarioService.CreateScenario(name, new List<string> { strategy.Name });
await _scenarioService.CreateScenario(name, new List<string> { strategy.Name });
}
private void SetupEmaTrend()
private async Task SetupEmaTrend()
{
var name = "Ema200Trend";
var strategy = _scenarioService.CreateStrategy(IndicatorType.EmaTrend,
var strategy = await _scenarioService.CreateStrategy(IndicatorType.EmaTrend,
name,
period: 200);
_scenarioService.CreateScenario(name, new List<string> { strategy.Name });
await _scenarioService.CreateScenario(name, new List<string> { strategy.Name });
}
private void SetupEmaCross()
private async Task SetupEmaCross()
{
var name = "Ema200Cross";
var strategy = _scenarioService.CreateStrategy(IndicatorType.EmaCross,
var strategy = await _scenarioService.CreateStrategy(IndicatorType.EmaCross,
name,
period: 200);
_scenarioService.CreateScenario(name, new List<string> { strategy.Name });
await _scenarioService.CreateScenario(name, new List<string> { strategy.Name });
}
public async Task<bool> CreateDefaultConfiguration(User user)
@@ -212,7 +201,7 @@ public class SettingsService : ISettingsService
await _moneyManagementService.CreateOrUpdateMoneyManagement(user, defaultMoneyManagement);
// Create default Strategy (StcTrend)
var defaultStrategy = _scenarioService.CreateIndicatorForUser(
var defaultStrategy = await _scenarioService.CreateIndicatorForUser(
user,
IndicatorType.Stc,
"Stc",
@@ -226,7 +215,7 @@ public class SettingsService : ISettingsService
// Create default Scenario containing the strategy
var strategyNames = new List<string> { defaultStrategy.Name };
var defaultScenario = _scenarioService.CreateScenarioForUser(
var defaultScenario = await _scenarioService.CreateScenarioForUser(
user,
"STC Scenario",
strategyNames