Skip to content

Commit c564420

Browse files
committed
Fix live trading charts sampling logic on extended market hours
1 parent 7602c5b commit c564420

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

Engine/Results/LiveTradingResultHandler.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,12 @@ public virtual void ProcessSynchronousEvents(bool forceProcess = false)
11191119
/// </summary>
11201120
public override void OnSecuritiesChanged(SecurityChanges changes)
11211121
{
1122-
if (_sampleChartAlways)
1122+
// the security that made us sample always might have been removed, if that's the case we need to check again if we should sample always or not
1123+
if (_sampleChartAlways && changes.RemovedSecurities.Count > 0 && changes.RemovedSecurities.Any(x => ShouldSampleChartsAlways(x.Symbol)))
1124+
{
1125+
_sampleChartAlways = false;
1126+
}
1127+
if (_sampleChartAlways)
11231128
{
11241129
return;
11251130
}
@@ -1133,10 +1138,7 @@ public override void OnSecuritiesChanged(SecurityChanges changes)
11331138
}
11341139

11351140
// if the user added Crypto, Forex, Daily or an extended market hours subscription just sample always, one way trip.
1136-
_sampleChartAlways = symbol.SecurityType == QuantConnect.SecurityType.Crypto
1137-
|| symbol.SecurityType == QuantConnect.SecurityType.Forex
1138-
|| Algorithm.SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(symbol)
1139-
.Any(config => config.ExtendedMarketHours || config.Resolution == Resolution.Daily);
1141+
_sampleChartAlways = ShouldSampleChartsAlways(symbol);
11401142
if (_sampleChartAlways)
11411143
{
11421144
// we set it once to true
@@ -1151,6 +1153,17 @@ public override void OnSecuritiesChanged(SecurityChanges changes)
11511153
}
11521154
}
11531155

1156+
/// <summary>
1157+
/// Checks whether the symbol subscription would make the result handler sample charts always
1158+
/// </summary>
1159+
private bool ShouldSampleChartsAlways(Symbol symbol)
1160+
{
1161+
return symbol.SecurityType == QuantConnect.SecurityType.Crypto
1162+
|| symbol.SecurityType == QuantConnect.SecurityType.Forex
1163+
|| Algorithm.SubscriptionManager.SubscriptionDataConfigService.GetSubscriptionDataConfigs(symbol)
1164+
.Any(config => config.ExtendedMarketHours);
1165+
}
1166+
11541167
/// <summary>
11551168
/// True if user exchange are open and we should update portfolio and benchmark value
11561169
/// </summary>

0 commit comments

Comments
 (0)