Skip to content

Commit

Permalink
Fix issue QuantConnect#8392: Handle fill-forward data in IdentityData…
Browse files Browse the repository at this point in the history
…Consolidator
  • Loading branch information
aneelc committed Dec 11, 2024
1 parent 085476a commit 46a0219
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions Tests/Common/Data/IdentityDataConsolidatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using NUnit.Framework;
using QuantConnect.Data.Consolidators;
using QuantConnect.Data.Market;
using QuantConnect.Data;

namespace QuantConnect.Tests.Common.Data
{
Expand Down Expand Up @@ -62,11 +63,11 @@ public void IgnoresNonTickDataWithSameTimestamps()
{
count++;
};
var tradeBar = new TradeBar{EndTime = reference};

var tradeBar = new TradeBar { EndTime = reference };
identity.Update(tradeBar);

tradeBar = (TradeBar) tradeBar.Clone();
tradeBar = (TradeBar)tradeBar.Clone();
identity.Update(tradeBar);

Assert.AreEqual(1, count);
Expand All @@ -92,5 +93,40 @@ public void AcceptsTickDataWithSameTimestamps()

Assert.AreEqual(2, count);
}

[Test]
public void TriggersOnDataConsolidatedForFillForwardData()
{
// Arrange
using (var consolidator = new IdentityDataConsolidator<TradeBar>())
{
// Create a TradeBar instance
var fillForwardData = new TradeBar
{
Time = DateTime.UtcNow,
EndTime = DateTime.UtcNow.AddMinutes(1),
Value = 100
};

// Use reflection to set the IsFillForward property
var property = typeof(BaseData).GetProperty(
nameof(BaseData.IsFillForward),
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance);
property.SetValue(fillForwardData, true);

bool eventTriggered = false;

// Act
consolidator.DataConsolidated += (sender, consolidated) =>
{
eventTriggered = true;
};
consolidator.Update(fillForwardData);

// Assert
Assert.IsTrue(eventTriggered, "DataConsolidated event should trigger for fill-forward data.");
}
}
}
}

0 comments on commit 46a0219

Please sign in to comment.