More fix
This commit is contained in:
@@ -55,7 +55,18 @@ namespace Managing.Application.Backtesting
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<Backtest> RunScalpingBotBacktest(
|
||||
/// <summary>
|
||||
/// Runs a unified trading bot backtest with the specified configuration and date range.
|
||||
/// Automatically handles ScalpingBot and FlippingBot behavior based on config.BotType.
|
||||
/// </summary>
|
||||
/// <param name="config">The trading bot configuration</param>
|
||||
/// <param name="startDate">The start date for the backtest</param>
|
||||
/// <param name="endDate">The end date for the backtest</param>
|
||||
/// <param name="user">The user running the backtest</param>
|
||||
/// <param name="save">Whether to save the backtest results</param>
|
||||
/// <param name="initialCandles">Optional pre-loaded candles</param>
|
||||
/// <returns>The backtest results</returns>
|
||||
public async Task<Backtest> RunTradingBotBacktest(
|
||||
TradingBotConfig config,
|
||||
DateTime startDate,
|
||||
DateTime endDate,
|
||||
@@ -64,12 +75,17 @@ namespace Managing.Application.Backtesting
|
||||
List<Candle>? initialCandles = null)
|
||||
{
|
||||
var account = await GetAccountFromConfig(config);
|
||||
var scalpingBot = _botFactory.CreateBacktestScalpingBot(config);
|
||||
scalpingBot.LoadScenario(config.ScenarioName);
|
||||
scalpingBot.User = user;
|
||||
await scalpingBot.LoadAccount();
|
||||
|
||||
// Set FlipPosition based on BotType
|
||||
config.FlipPosition = config.BotType == BotType.FlippingBot;
|
||||
|
||||
var tradingBot = _botFactory.CreateBacktestTradingBot(config);
|
||||
tradingBot.LoadScenario(config.ScenarioName);
|
||||
tradingBot.User = user;
|
||||
await tradingBot.LoadAccount();
|
||||
|
||||
var candles = initialCandles ?? GetCandles(account, config.Ticker, config.Timeframe, startDate, endDate);
|
||||
var result = GetBacktestingResult(config, scalpingBot, candles);
|
||||
var result = GetBacktestingResult(config, tradingBot, candles);
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
@@ -88,6 +104,52 @@ namespace Managing.Application.Backtesting
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Runs a unified trading bot backtest with pre-loaded candles.
|
||||
/// Automatically handles ScalpingBot and FlippingBot behavior based on config.BotType.
|
||||
/// </summary>
|
||||
/// <param name="config">The trading bot configuration</param>
|
||||
/// <param name="candles">The candles to use for backtesting</param>
|
||||
/// <param name="user">The user running the backtest</param>
|
||||
/// <returns>The backtest results</returns>
|
||||
public async Task<Backtest> RunTradingBotBacktest(
|
||||
TradingBotConfig config,
|
||||
List<Candle> candles,
|
||||
User user = null)
|
||||
{
|
||||
var account = await GetAccountFromConfig(config);
|
||||
|
||||
// Set FlipPosition based on BotType
|
||||
config.FlipPosition = config.BotType == BotType.FlippingBot;
|
||||
|
||||
var tradingBot = _botFactory.CreateBacktestTradingBot(config);
|
||||
tradingBot.LoadScenario(config.ScenarioName);
|
||||
tradingBot.User = user;
|
||||
await tradingBot.LoadAccount();
|
||||
|
||||
var result = GetBacktestingResult(config, tradingBot, candles);
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
result.User = user;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Legacy methods - maintained for backward compatibility
|
||||
public async Task<Backtest> RunScalpingBotBacktest(
|
||||
TradingBotConfig config,
|
||||
DateTime startDate,
|
||||
DateTime endDate,
|
||||
User user = null,
|
||||
bool save = false,
|
||||
List<Candle>? initialCandles = null)
|
||||
{
|
||||
config.BotType = BotType.ScalpingBot; // Ensure correct type
|
||||
return await RunTradingBotBacktest(config, startDate, endDate, user, save, initialCandles);
|
||||
}
|
||||
|
||||
public async Task<Backtest> RunFlippingBotBacktest(
|
||||
TradingBotConfig config,
|
||||
DateTime startDate,
|
||||
@@ -96,30 +158,8 @@ namespace Managing.Application.Backtesting
|
||||
bool save = false,
|
||||
List<Candle>? initialCandles = null)
|
||||
{
|
||||
var account = await GetAccountFromConfig(config);
|
||||
var flippingBot = _botFactory.CreateBacktestFlippingBot(config);
|
||||
flippingBot.LoadScenario(config.ScenarioName);
|
||||
flippingBot.User = user;
|
||||
await flippingBot.LoadAccount();
|
||||
|
||||
var candles = initialCandles ?? GetCandles(account, config.Ticker, config.Timeframe, startDate, endDate);
|
||||
var result = GetBacktestingResult(config, flippingBot, candles);
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
result.User = user;
|
||||
}
|
||||
|
||||
// Set start and end dates
|
||||
result.StartDate = startDate;
|
||||
result.EndDate = endDate;
|
||||
|
||||
if (save)
|
||||
{
|
||||
_backtestRepository.InsertBacktestForUser(user, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
config.BotType = BotType.FlippingBot; // Ensure correct type
|
||||
return await RunTradingBotBacktest(config, startDate, endDate, user, save, initialCandles);
|
||||
}
|
||||
|
||||
public async Task<Backtest> RunScalpingBotBacktest(
|
||||
@@ -127,20 +167,8 @@ namespace Managing.Application.Backtesting
|
||||
List<Candle> candles,
|
||||
User user = null)
|
||||
{
|
||||
var account = await GetAccountFromConfig(config);
|
||||
var bot = _botFactory.CreateBacktestScalpingBot(config);
|
||||
bot.LoadScenario(config.ScenarioName);
|
||||
bot.User = user;
|
||||
await bot.LoadAccount();
|
||||
|
||||
var result = GetBacktestingResult(config, bot, candles);
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
result.User = user;
|
||||
}
|
||||
|
||||
return result;
|
||||
config.BotType = BotType.ScalpingBot; // Ensure correct type
|
||||
return await RunTradingBotBacktest(config, candles, user);
|
||||
}
|
||||
|
||||
public async Task<Backtest> RunFlippingBotBacktest(
|
||||
@@ -148,20 +176,8 @@ namespace Managing.Application.Backtesting
|
||||
List<Candle> candles,
|
||||
User user = null)
|
||||
{
|
||||
var account = await GetAccountFromConfig(config);
|
||||
var bot = _botFactory.CreateBacktestFlippingBot(config);
|
||||
bot.LoadScenario(config.ScenarioName);
|
||||
bot.User = user;
|
||||
await bot.LoadAccount();
|
||||
|
||||
var result = GetBacktestingResult(config, bot, candles);
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
result.User = user;
|
||||
}
|
||||
|
||||
return result;
|
||||
config.BotType = BotType.FlippingBot; // Ensure correct type
|
||||
return await RunTradingBotBacktest(config, candles, user);
|
||||
}
|
||||
|
||||
private async Task<Account> GetAccountFromConfig(TradingBotConfig config)
|
||||
|
||||
Reference in New Issue
Block a user