Skip to content

Commit

Permalink
Add new unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
JosueNina committed Jan 16, 2025
1 parent 60ce1b1 commit 7b2d0e0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
36 changes: 18 additions & 18 deletions Algorithm/QCAlgorithm.History.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,29 +1095,29 @@ private IEnumerable<SubscriptionDataConfig> GetMatchingSubscriptions(Symbol symb
return configs.Where(s => s.TickType != TickType.Quote);
}

type = typeof(QuoteBar);
var entry = MarketHoursDatabase.GetEntry(symbol, new[] { type });

// Create a new SubscriptionDataConfig
var newConfig = new SubscriptionDataConfig(
type,
symbol,
resolution.Value,
entry.DataTimeZone,
entry.ExchangeHours.TimeZone,
UniverseSettings.FillForward,
UniverseSettings.ExtendedMarketHours,
false);

// If no existing configuration for the Quote tick type, add the new config
if (!configs.Any(config => config.TickType == TickType.Quote))
if (!configs.Any(config => config.TickType == TickType.Quote) && type == null)
{
configs.Add(newConfig);
}
type = LeanData.GetDataType(resolution.Value, TickType.Quote);
var entry = MarketHoursDatabase.GetEntry(symbol, new[] { type });

// Create a new SubscriptionDataConfig
var newConfig = new SubscriptionDataConfig(
type,
symbol,
resolution.Value,
entry.DataTimeZone,
entry.ExchangeHours.TimeZone,
UniverseSettings.FillForward,
UniverseSettings.ExtendedMarketHours,
false, tickType: TickType.Quote);

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

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

if (symbol.IsCanonical() && configs.Count > 1)
Expand Down
21 changes: 21 additions & 0 deletions Tests/Algorithm/AlgorithmHistoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,27 @@ public void VerifyReceivedDataBasedOnHistoryResolutionOnly(Resolution historyRes
Assert.AreEqual(expected, bothSymbolsHaveQuotes);
}

[Test]
public void VerifyHistorySupportsSpecificDataTypes()
{
var algorithm = GetAlgorithm(new DateTime(2013, 10, 8));
algorithm.SetStartDate(2013, 10, 10);
var spy = algorithm.AddEquity("SPY", Resolution.Minute).Symbol;
var ibm = algorithm.AddEquity("IBM", Resolution.Hour).Symbol;

var tradeBarHistory = algorithm.History<TradeBar>(new[] { spy, ibm }, TimeSpan.FromDays(1), Resolution.Minute).ToList();
var generalHistory = algorithm.History(new[] { spy, ibm }, TimeSpan.FromDays(1), Resolution.Minute).ToList();

// Extract all TradeBars
var tradeBars = tradeBarHistory.SelectMany(slice => slice.Values).ToList();

// Filter and extract only TradeBars from the general history
var filteredTradeBars = generalHistory.SelectMany(slice => slice.AllData).Where(e => e.DataType == MarketDataType.TradeBar).ToList();

// Assert that the count of TradeBars in both methods is consistent
Assert.AreEqual(filteredTradeBars.Count, tradeBars.Count);
}

[TestCase(Language.CSharp)]
[TestCase(Language.Python)]
public void TickResolutionPeriodBasedHistoryRequestThrowsException(Language language)
Expand Down

0 comments on commit 7b2d0e0

Please sign in to comment.