Push merge conflict

This commit is contained in:
2025-07-04 11:02:53 +07:00
parent 88f195c0ca
commit 59c5de7df7
27 changed files with 1133 additions and 1118 deletions

View File

@@ -10,7 +10,6 @@ using Managing.Domain.Strategies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using static Managing.Common.Enums;
namespace Managing.Api.Controllers;
@@ -192,15 +191,14 @@ public class BacktestController : BaseController
ScenarioName = request.Config.ScenarioName,
Scenario = scenario, // Use the converted scenario object
Timeframe = request.Config.Timeframe,
IsForWatchingOnly = request.WatchOnly,
BotTradingBalance = request.Balance,
BotType = request.Config.BotType,
IsForWatchingOnly = request.Config.IsForWatchingOnly,
BotTradingBalance = request.Config.BotTradingBalance,
IsForBacktest = true,
CooldownPeriod = request.Config.CooldownPeriod,
MaxLossStreak = request.Config.MaxLossStreak,
MaxPositionTimeHours = request.Config.MaxPositionTimeHours,
FlipOnlyWhenInProfit = request.Config.FlipOnlyWhenInProfit,
FlipPosition = request.Config.BotType == BotType.FlippingBot, // Computed based on BotType
FlipPosition = request.Config.FlipPosition, // Computed based on BotType
Name = request.Config.Name ??
$"Backtest-{request.Config.ScenarioName ?? request.Config.Scenario?.Name ?? "Custom"}-{DateTime.UtcNow:yyyyMMdd-HHmmss}",
CloseEarlyWhenProfitable = request.Config.CloseEarlyWhenProfitable,
@@ -210,21 +208,12 @@ public class BacktestController : BaseController
UseForDynamicStopLoss = request.Config.UseForDynamicStopLoss
};
switch (request.Config.BotType)
{
case BotType.SimpleBot:
// SimpleBot backtest not implemented yet
break;
case BotType.ScalpingBot:
case BotType.FlippingBot:
backtestResult = await _backtester.RunTradingBotBacktest(
backtestConfig,
request.StartDate,
request.EndDate,
user,
request.Save);
break;
}
backtestResult = await _backtester.RunTradingBotBacktest(
backtestConfig,
request.StartDate,
request.EndDate,
user,
request.Save);
await NotifyBacktesingSubscriberAsync(backtestResult);
@@ -281,16 +270,6 @@ public class RunBacktestRequest
/// </summary>
public DateTime EndDate { get; set; }
/// <summary>
/// The starting balance for the backtest
/// </summary>
public decimal Balance { get; set; }
/// <summary>
/// Whether to only watch the backtest without executing trades
/// </summary>
public bool WatchOnly { get; set; } = false;
/// <summary>
/// Whether to save the backtest results
/// </summary>

View File

@@ -224,7 +224,6 @@ public class BotController : BaseController
Timeframe = request.Config.Timeframe,
IsForWatchingOnly = request.Config.IsForWatchingOnly,
BotTradingBalance = request.Config.BotTradingBalance,
BotType = request.Config.BotType,
CooldownPeriod = request.Config.CooldownPeriod,
MaxLossStreak = request.Config.MaxLossStreak,
MaxPositionTimeHours = request.Config.MaxPositionTimeHours,
@@ -236,7 +235,7 @@ public class BotController : BaseController
UseForDynamicStopLoss = request.Config.UseForDynamicStopLoss,
// Set computed/default properties
IsForBacktest = false,
FlipPosition = request.Config.BotType == BotType.FlippingBot,
FlipPosition = request.Config.FlipPosition,
Name = request.Config.Name
};
@@ -256,12 +255,11 @@ public class BotController : BaseController
/// <summary>
/// Stops a bot specified by type and name.
/// </summary>
/// <param name="botType">The type of the bot to stop.</param>
/// <param name="identifier">The identifier of the bot to stop.</param>
/// <returns>A string indicating the result of the stop operation.</returns>
[HttpGet]
[Route("Stop")]
public async Task<ActionResult<string>> Stop(BotType botType, string identifier)
public async Task<ActionResult<string>> Stop(string identifier)
{
try
{
@@ -271,8 +269,8 @@ public class BotController : BaseController
return Forbid("You don't have permission to stop this bot");
}
var result = await _mediator.Send(new StopBotCommand(botType, identifier));
_logger.LogInformation($"{botType} type with identifier {identifier} is now {result}");
var result = await _mediator.Send(new StopBotCommand(identifier));
_logger.LogInformation($"Bot identifier {identifier} is now {result}");
await NotifyBotSubscriberAsync();
@@ -343,7 +341,7 @@ public class BotController : BaseController
foreach (var bot in userBots)
{
await _mediator.Send(new StopBotCommand(bot.Config.BotType, bot.Identifier));
await _mediator.Send(new StopBotCommand(bot.Identifier));
await _hubContext.Clients.All.SendAsync("SendNotification",
$"Bot {bot.Identifier} paused by {user.Name}.", "Info");
}
@@ -422,7 +420,8 @@ public class BotController : BaseController
{
// We can't directly restart a bot with just BotType and Name
// Instead, stop the bot and then retrieve the backup to start it again
await _mediator.Send(new StopBotCommand(bot.Config.BotType, bot.Identifier));
await _mediator.Send(
new StopBotCommand(bot.Identifier));
// Get the saved bot backup
var backup = _botService.GetBotBackup(bot.Identifier);
@@ -776,7 +775,6 @@ public class BotController : BaseController
Timeframe = request.Config.Timeframe,
IsForWatchingOnly = request.Config.IsForWatchingOnly,
BotTradingBalance = request.Config.BotTradingBalance,
BotType = request.Config.BotType,
CooldownPeriod = request.Config.CooldownPeriod,
MaxLossStreak = request.Config.MaxLossStreak,
MaxPositionTimeHours = request.Config.MaxPositionTimeHours,
@@ -788,7 +786,7 @@ public class BotController : BaseController
UseForDynamicStopLoss = request.Config.UseForDynamicStopLoss,
// Set computed/default properties
IsForBacktest = false,
FlipPosition = request.Config.BotType == BotType.FlippingBot,
FlipPosition = request.Config.FlipPosition,
Name = request.Config.Name
};