Fix backtests

This commit is contained in:
2025-04-25 12:48:50 +07:00
parent 7ddc0328f6
commit 2e6afe3869
2 changed files with 13 additions and 6 deletions

View File

@@ -292,7 +292,14 @@ public class TradingBot : Bot, ITradingBot
foreach (var signal in Signals.Where(s => s.Status == SignalStatus.PositionOpen))
{
var positionForSignal = Positions.FirstOrDefault(p => p.SignalIdentifier == signal.Identifier);
await UpdatePosition(signal, positionForSignal);
if (positionForSignal == null)
{
await LogInformation($"Cannot find position for signal {signal.Identifier}");
}
else
{
await UpdatePosition(signal, positionForSignal);
}
}
// Open position for signal waiting for a position open
@@ -456,7 +463,7 @@ public class TradingBot : Bot, ITradingBot
catch (Exception ex)
{
Logger.LogError(ex, ex.Message);
SentrySdk.CaptureException(ex);
//SentrySdk.CaptureException(ex);
return;
}
}
@@ -519,7 +526,7 @@ public class TradingBot : Bot, ITradingBot
}
await LogInformation(
$"Open position - Date: {signal.Date:T} - SignalIdentifier : {signal.Identifier} - Strategie : {signal.StrategyType}");
$"Open position - Date: {signal.Date:T} - SignalIdentifier : {signal.Identifier}");
try
{
@@ -542,7 +549,6 @@ public class TradingBot : Bot, ITradingBot
if (position != null)
{
position.SignalIdentifier = signal.Identifier;
Positions.Add(position);
if (position.Open.Status != TradeStatus.Cancelled)
@@ -827,7 +833,7 @@ public class TradingBot : Bot, ITradingBot
ScenarioName = data.ScenarioName;
AccountName = data.AccountName;
IsForWatchingOnly = data.IsForWatchingOnly;
// Restore the startup time if it was previously saved
if (data.StartupTime != DateTime.MinValue)
{