Skip to content

Commit 7b2d0e0

Browse files
committed
Add new unit test
1 parent 60ce1b1 commit 7b2d0e0

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

Algorithm/QCAlgorithm.History.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,29 +1095,29 @@ private IEnumerable<SubscriptionDataConfig> GetMatchingSubscriptions(Symbol symb
10951095
return configs.Where(s => s.TickType != TickType.Quote);
10961096
}
10971097

1098-
type = typeof(QuoteBar);
1099-
var entry = MarketHoursDatabase.GetEntry(symbol, new[] { type });
1100-
1101-
// Create a new SubscriptionDataConfig
1102-
var newConfig = new SubscriptionDataConfig(
1103-
type,
1104-
symbol,
1105-
resolution.Value,
1106-
entry.DataTimeZone,
1107-
entry.ExchangeHours.TimeZone,
1108-
UniverseSettings.FillForward,
1109-
UniverseSettings.ExtendedMarketHours,
1110-
false);
11111098

11121099
// If no existing configuration for the Quote tick type, add the new config
1113-
if (!configs.Any(config => config.TickType == TickType.Quote))
1100+
if (!configs.Any(config => config.TickType == TickType.Quote) && type == null)
11141101
{
1115-
configs.Add(newConfig);
1116-
}
1102+
type = LeanData.GetDataType(resolution.Value, TickType.Quote);
1103+
var entry = MarketHoursDatabase.GetEntry(symbol, new[] { type });
1104+
1105+
// Create a new SubscriptionDataConfig
1106+
var newConfig = new SubscriptionDataConfig(
1107+
type,
1108+
symbol,
1109+
resolution.Value,
1110+
entry.DataTimeZone,
1111+
entry.ExchangeHours.TimeZone,
1112+
UniverseSettings.FillForward,
1113+
UniverseSettings.ExtendedMarketHours,
1114+
false, tickType: TickType.Quote);
11171115

1118-
// Sort the configs in descending order based on tick type
1119-
configs = configs.OrderByDescending(config => GetTickTypeOrder(config.SecurityType, config.TickType)).ToList();
1116+
configs.Add(newConfig);
11201117

1118+
// Sort the configs in descending order based on tick type
1119+
configs = configs.OrderByDescending(config => GetTickTypeOrder(config.SecurityType, config.TickType)).ToList();
1120+
}
11211121
}
11221122

11231123
if (symbol.IsCanonical() && configs.Count > 1)

Tests/Algorithm/AlgorithmHistoryTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,27 @@ public void VerifyReceivedDataBasedOnHistoryResolutionOnly(Resolution historyRes
365365
Assert.AreEqual(expected, bothSymbolsHaveQuotes);
366366
}
367367

368+
[Test]
369+
public void VerifyHistorySupportsSpecificDataTypes()
370+
{
371+
var algorithm = GetAlgorithm(new DateTime(2013, 10, 8));
372+
algorithm.SetStartDate(2013, 10, 10);
373+
var spy = algorithm.AddEquity("SPY", Resolution.Minute).Symbol;
374+
var ibm = algorithm.AddEquity("IBM", Resolution.Hour).Symbol;
375+
376+
var tradeBarHistory = algorithm.History<TradeBar>(new[] { spy, ibm }, TimeSpan.FromDays(1), Resolution.Minute).ToList();
377+
var generalHistory = algorithm.History(new[] { spy, ibm }, TimeSpan.FromDays(1), Resolution.Minute).ToList();
378+
379+
// Extract all TradeBars
380+
var tradeBars = tradeBarHistory.SelectMany(slice => slice.Values).ToList();
381+
382+
// Filter and extract only TradeBars from the general history
383+
var filteredTradeBars = generalHistory.SelectMany(slice => slice.AllData).Where(e => e.DataType == MarketDataType.TradeBar).ToList();
384+
385+
// Assert that the count of TradeBars in both methods is consistent
386+
Assert.AreEqual(filteredTradeBars.Count, tradeBars.Count);
387+
}
388+
368389
[TestCase(Language.CSharp)]
369390
[TestCase(Language.Python)]
370391
public void TickResolutionPeriodBasedHistoryRequestThrowsException(Language language)

0 commit comments

Comments
 (0)