Remove candle from backtest return + fix message when good backtest
This commit is contained in:
@@ -383,8 +383,7 @@ public class BacktestExecutor
|
||||
var finalRequestId = requestId != null ? Guid.Parse(requestId) : Guid.NewGuid();
|
||||
|
||||
// Create backtest result with conditional candles and indicators values
|
||||
var result = new Backtest(config, tradingBot.Positions, tradingBot.Signals,
|
||||
withCandles ? candles : new HashSet<Candle>())
|
||||
var result = new Backtest(config, tradingBot.Positions, tradingBot.Signals)
|
||||
{
|
||||
FinalPnl = realizedPnl, // Realized PnL before fees
|
||||
WinRate = winRate,
|
||||
@@ -485,7 +484,9 @@ public class BacktestExecutor
|
||||
string.Join(", ", bottlenecks));
|
||||
}
|
||||
|
||||
_logger.LogInformation("🎯 Backtest completed successfully - RequestId: {RequestId} - Score: {Score} - Realized PnL: {RealizedPnl} - Net PnL: {NetPnl} - Fees: {Fees}", finalRequestId, result.Score, result.FinalPnl, result.NetPnl, result.Fees);
|
||||
_logger.LogInformation(
|
||||
"🎯 Backtest completed successfully - RequestId: {RequestId} - Score: {Score} - Realized PnL: {RealizedPnl} - Net PnL: {NetPnl} - Fees: {Fees}",
|
||||
finalRequestId, result.Score, result.FinalPnl, result.NetPnl, result.Fees);
|
||||
|
||||
// Convert Backtest to LightBacktest
|
||||
return ConvertToLightBacktest(result);
|
||||
|
||||
@@ -4,7 +4,6 @@ using Managing.Application.Abstractions.Repositories;
|
||||
using Managing.Application.Abstractions.Services;
|
||||
using Managing.Application.Abstractions.Shared;
|
||||
using Managing.Application.Hubs;
|
||||
using Managing.Domain.Accounts;
|
||||
using Managing.Domain.Backtests;
|
||||
using Managing.Domain.Bots;
|
||||
using Managing.Domain.Candles;
|
||||
@@ -136,7 +135,8 @@ namespace Managing.Application.Backtests
|
||||
var startDate = candles.Min(c => c.Date);
|
||||
var endDate = candles.Max(c => c.Date);
|
||||
|
||||
return await RunTradingBotBacktest(config, startDate, endDate, user, false, withCandles, requestId, metadata);
|
||||
return await RunTradingBotBacktest(config, startDate, endDate, user, false, withCandles, requestId,
|
||||
metadata);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteBacktestAsync(string id)
|
||||
@@ -215,31 +215,6 @@ namespace Managing.Application.Backtests
|
||||
if (backtest == null)
|
||||
return null;
|
||||
|
||||
if (backtest.Candles == null || backtest.Candles.Count == 0 || backtest.Candles.Count < 10)
|
||||
{
|
||||
try
|
||||
{
|
||||
var account = new Account
|
||||
{ Name = backtest.Config.AccountName, Exchange = TradingExchanges.Evm };
|
||||
|
||||
var candles = await _exchangeService.GetCandlesInflux(
|
||||
account.Exchange,
|
||||
backtest.Config.Ticker,
|
||||
backtest.StartDate,
|
||||
backtest.Config.Timeframe,
|
||||
backtest.EndDate);
|
||||
|
||||
if (candles != null && candles.Count > 0)
|
||||
{
|
||||
backtest.Candles = candles;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Failed to retrieve candles for backtest {Id}", id);
|
||||
}
|
||||
}
|
||||
|
||||
return backtest;
|
||||
}
|
||||
|
||||
@@ -348,12 +323,12 @@ namespace Managing.Application.Backtests
|
||||
{
|
||||
// Generate backtest requests from variants (same logic as BundleBacktestGrain)
|
||||
var backtestRequests = await GenerateBacktestRequestsFromVariants(bundleRequest);
|
||||
|
||||
|
||||
if (backtestRequests != null && backtestRequests.Any())
|
||||
{
|
||||
// Create jobs for all variants
|
||||
await _jobService.CreateBundleJobsAsync(bundleRequest, backtestRequests);
|
||||
|
||||
|
||||
_logger.LogInformation(
|
||||
"Created {JobCount} backtest jobs for bundle request {BundleRequestId}",
|
||||
backtestRequests.Count, bundleRequest.RequestId);
|
||||
@@ -380,12 +355,12 @@ namespace Managing.Application.Backtests
|
||||
{
|
||||
// Generate backtest requests from variants
|
||||
var backtestRequests = await GenerateBacktestRequestsFromVariants(bundleRequest);
|
||||
|
||||
|
||||
if (backtestRequests != null && backtestRequests.Any())
|
||||
{
|
||||
// Create jobs for all variants
|
||||
await _jobService.CreateBundleJobsAsync(bundleRequest, backtestRequests);
|
||||
|
||||
|
||||
_logger.LogInformation(
|
||||
"Created {JobCount} backtest jobs for bundle request {BundleRequestId}",
|
||||
backtestRequests.Count, bundleRequest.RequestId);
|
||||
@@ -399,8 +374,8 @@ namespace Managing.Application.Backtests
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex,
|
||||
"Error creating jobs for bundle request {BundleRequestId}",
|
||||
_logger.LogError(ex,
|
||||
"Error creating jobs for bundle request {BundleRequestId}",
|
||||
bundleRequest.RequestId);
|
||||
throw;
|
||||
}
|
||||
@@ -431,7 +406,9 @@ namespace Managing.Application.Backtests
|
||||
}
|
||||
|
||||
// Get the first account for the user
|
||||
var accounts = await _accountService.GetAccountsByUserAsync(bundleRequest.User, hideSecrets: true, getBalance: false);
|
||||
var accounts =
|
||||
await _accountService.GetAccountsByUserAsync(bundleRequest.User, hideSecrets: true,
|
||||
getBalance: false);
|
||||
var firstAccount = accounts.FirstOrDefault();
|
||||
|
||||
if (firstAccount == null)
|
||||
@@ -573,15 +550,17 @@ namespace Managing.Application.Backtests
|
||||
return (bundleRequests, totalCount);
|
||||
}
|
||||
|
||||
public async Task<(IEnumerable<BundleBacktestRequest> BundleRequests, int TotalCount)> GetBundleBacktestRequestsPaginatedAsync(
|
||||
int page,
|
||||
int pageSize,
|
||||
BundleBacktestRequestSortableColumn sortBy = BundleBacktestRequestSortableColumn.CreatedAt,
|
||||
string sortOrder = "desc",
|
||||
BundleBacktestRequestsFilter? filter = null)
|
||||
public async Task<(IEnumerable<BundleBacktestRequest> BundleRequests, int TotalCount)>
|
||||
GetBundleBacktestRequestsPaginatedAsync(
|
||||
int page,
|
||||
int pageSize,
|
||||
BundleBacktestRequestSortableColumn sortBy = BundleBacktestRequestSortableColumn.CreatedAt,
|
||||
string sortOrder = "desc",
|
||||
BundleBacktestRequestsFilter? filter = null)
|
||||
{
|
||||
var (bundleRequests, totalCount) =
|
||||
await _backtestRepository.GetBundleBacktestRequestsPaginatedAsync(page, pageSize, sortBy, sortOrder, filter);
|
||||
await _backtestRepository.GetBundleBacktestRequestsPaginatedAsync(page, pageSize, sortBy, sortOrder,
|
||||
filter);
|
||||
return (bundleRequests, totalCount);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user