Update genetic impl
This commit is contained in:
@@ -218,7 +218,8 @@ public class BacktestController : BaseController
|
||||
request.EndDate,
|
||||
user,
|
||||
request.Save,
|
||||
request.WithCandles);
|
||||
request.WithCandles,
|
||||
null); // No requestId for regular backtests
|
||||
|
||||
await NotifyBacktesingSubscriberAsync(backtestResult);
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace Managing.Application.Abstractions.Services
|
||||
/// <param name="user">The user running the backtest (optional)</param>
|
||||
/// <param name="save">Whether to save the backtest results</param>
|
||||
/// <param name="withCandles">Whether to include candles and indicators values in the response</param>
|
||||
/// <param name="requestId">The request ID to associate with this backtest (optional)</param>
|
||||
/// <returns>The backtest results</returns>
|
||||
Task<Backtest> RunTradingBotBacktest(
|
||||
TradingBotConfig config,
|
||||
@@ -24,7 +25,8 @@ namespace Managing.Application.Abstractions.Services
|
||||
DateTime endDate,
|
||||
User user = null,
|
||||
bool save = false,
|
||||
bool withCandles = false);
|
||||
bool withCandles = false,
|
||||
string requestId = null);
|
||||
|
||||
/// <summary>
|
||||
/// Runs a trading bot backtest with pre-loaded candles.
|
||||
@@ -34,12 +36,14 @@ namespace Managing.Application.Abstractions.Services
|
||||
/// <param name="candles">The candles to use for backtesting</param>
|
||||
/// <param name="user">The user running the backtest (optional)</param>
|
||||
/// <param name="withCandles">Whether to include candles and indicators values in the response</param>
|
||||
/// <param name="requestId">The request ID to associate with this backtest (optional)</param>
|
||||
/// <returns>The backtest results</returns>
|
||||
Task<Backtest> RunTradingBotBacktest(
|
||||
TradingBotConfig config,
|
||||
List<Candle> candles,
|
||||
User user = null,
|
||||
bool withCandles = false);
|
||||
bool withCandles = false,
|
||||
string requestId = null);
|
||||
|
||||
// Additional methods for backtest management
|
||||
bool DeleteBacktest(string id);
|
||||
|
||||
@@ -69,6 +69,7 @@ namespace Managing.Application.Backtesting
|
||||
/// <param name="user">The user running the backtest (optional)</param>
|
||||
/// <param name="save">Whether to save the backtest results</param>
|
||||
/// <param name="withCandles">Whether to include candles and indicators values in the response</param>
|
||||
/// <param name="requestId">The request ID to associate with this backtest (optional)</param>
|
||||
/// <returns>The backtest results</returns>
|
||||
public async Task<Backtest> RunTradingBotBacktest(
|
||||
TradingBotConfig config,
|
||||
@@ -76,12 +77,13 @@ namespace Managing.Application.Backtesting
|
||||
DateTime endDate,
|
||||
User user = null,
|
||||
bool save = false,
|
||||
bool withCandles = false)
|
||||
bool withCandles = false,
|
||||
string requestId = null)
|
||||
{
|
||||
var account = await GetAccountFromConfig(config);
|
||||
var candles = GetCandles(account, config.Ticker, config.Timeframe, startDate, endDate);
|
||||
|
||||
var result = await RunBacktestWithCandles(config, candles, user, withCandles);
|
||||
var result = await RunBacktestWithCandles(config, candles, user, withCandles, requestId);
|
||||
|
||||
// Set start and end dates
|
||||
result.StartDate = startDate;
|
||||
@@ -108,9 +110,10 @@ namespace Managing.Application.Backtesting
|
||||
TradingBotConfig config,
|
||||
List<Candle> candles,
|
||||
User user = null,
|
||||
bool withCandles = false)
|
||||
bool withCandles = false,
|
||||
string requestId = null)
|
||||
{
|
||||
return await RunBacktestWithCandles(config, candles, user, withCandles);
|
||||
return await RunBacktestWithCandles(config, candles, user, withCandles, requestId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -120,7 +123,8 @@ namespace Managing.Application.Backtesting
|
||||
TradingBotConfig config,
|
||||
List<Candle> candles,
|
||||
User user = null,
|
||||
bool withCandles = false)
|
||||
bool withCandles = false,
|
||||
string requestId = null)
|
||||
{
|
||||
var tradingBot = _botFactory.CreateBacktestTradingBot(config);
|
||||
|
||||
@@ -136,7 +140,7 @@ namespace Managing.Application.Backtesting
|
||||
tradingBot.User = user;
|
||||
await tradingBot.LoadAccount();
|
||||
|
||||
var result = await GetBacktestingResult(config, tradingBot, candles, user, withCandles);
|
||||
var result = await GetBacktestingResult(config, tradingBot, candles, user, withCandles, requestId);
|
||||
|
||||
if (user != null)
|
||||
{
|
||||
@@ -178,7 +182,8 @@ namespace Managing.Application.Backtesting
|
||||
ITradingBot bot,
|
||||
List<Candle> candles,
|
||||
User user = null,
|
||||
bool withCandles = false)
|
||||
bool withCandles = false,
|
||||
string requestId = null)
|
||||
{
|
||||
if (candles == null || candles.Count == 0)
|
||||
{
|
||||
@@ -267,7 +272,8 @@ namespace Managing.Application.Backtesting
|
||||
? AggregateValues(indicatorsValues, bot.IndicatorsValues)
|
||||
: new Dictionary<IndicatorType, IndicatorsResultBase>(),
|
||||
Score = score,
|
||||
Id = Guid.NewGuid().ToString()
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
RequestId = requestId
|
||||
};
|
||||
|
||||
// Send notification if backtest meets criteria
|
||||
|
||||
@@ -293,7 +293,8 @@ public class TradingBotFitness : IFitness
|
||||
_request.EndDate,
|
||||
_request.User,
|
||||
false, // Don't save individual backtests
|
||||
false // Don't include candles
|
||||
false, // Don't include candles
|
||||
_request.RequestId
|
||||
).Result;
|
||||
|
||||
// Calculate fitness based on backtest results
|
||||
|
||||
@@ -57,6 +57,7 @@ public class Backtest
|
||||
[Required] public User User { get; set; }
|
||||
[Required] public Dictionary<IndicatorType, IndicatorsResultBase> IndicatorsValues { get; set; }
|
||||
[Required] public double Score { get; set; }
|
||||
public string RequestId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new TradingBotConfig based on this backtest's configuration for starting a live bot.
|
||||
|
||||
@@ -22,5 +22,6 @@ namespace Managing.Infrastructure.Databases.MongoDb.Collections
|
||||
public PerformanceMetrics Statistics { get; set; }
|
||||
public double Score { get; set; }
|
||||
public string Identifier { get; set; }
|
||||
public string RequestId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -149,7 +149,8 @@ public static class MongoMappers
|
||||
Statistics = b.Statistics,
|
||||
StartDate = b.StartDate,
|
||||
EndDate = b.EndDate,
|
||||
Score = b.Score
|
||||
Score = b.Score,
|
||||
RequestId = b.RequestId
|
||||
};
|
||||
|
||||
return bTest;
|
||||
@@ -177,6 +178,7 @@ public static class MongoMappers
|
||||
StartDate = result.StartDate,
|
||||
EndDate = result.EndDate,
|
||||
Score = result.Score,
|
||||
RequestId = result.RequestId
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user