Delete backtest by id and with filters

This commit is contained in:
2025-07-11 22:05:46 +07:00
parent 9714da1eb9
commit 79f0cd20c1
9 changed files with 239 additions and 69 deletions

View File

@@ -143,8 +143,7 @@ namespace Managing.Application.Backtesting
tradingBot.User = user;
await tradingBot.LoadAccount();
var result =
await GetBacktestingResult(config, tradingBot, candles, user, withCandles, requestId, metadata);
var result = await GetBacktestingResult(config, tradingBot, candles, user, withCandles, requestId, metadata);
if (user != null)
{
@@ -297,25 +296,8 @@ namespace Managing.Application.Backtesting
{
try
{
// Check if backtest meets criteria: score > 85, at least 5 positions, winrate > 65%, risk-reward >= 1.5:1
var score = backtest.Score;
var tradeCount = backtest.Positions?.Count ?? 0;
var winRate = backtest.WinRate;
// Calculate risk-reward ratio from money management settings
var riskRewardRatio = 0.0;
if (backtest.Config.MoneyManagement != null)
{
var stopLoss = (double)backtest.Config.MoneyManagement.StopLoss;
var takeProfit = (double)backtest.Config.MoneyManagement.TakeProfit;
if (stopLoss > 0 && takeProfit > 0)
{
riskRewardRatio = takeProfit / stopLoss;
}
}
if (score > 85 && tradeCount >= 5 && winRate > 65 && riskRewardRatio >= 1.5)
if (backtest.Score > 80)
{
await _messengerService.SendBacktestNotification(backtest);
}
@@ -466,6 +448,20 @@ namespace Managing.Application.Backtesting
}
}
public bool DeleteBacktestsByIdsForUser(User user, IEnumerable<string> ids)
{
try
{
_backtestRepository.DeleteBacktestsByIdsForUser(user, ids);
return true;
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to delete backtests for user {UserName}", user.Name);
return false;
}
}
public bool DeleteBacktestsByUser(User user)
{
try