Skip to content

CanonicalDataDownloaderDecorator drops the first data point of a canonical download #10002

Closed

Description

@econstantin

Expected Behavior

CanonicalDataDownloaderDecorator.GetContractsData returns every data point that the contract downloads produce.

Actual Behavior

It drops 1 data point: the first one that any contract adds. The download exits with code 0 and logs no error. The contracts download in parallel, so 2 downloads of the same window can lose different data points.

Potential Solution

GetContractsData calls .Any() on blockingCollection.GetConsumingEnumerable(). A consuming enumerable removes each item that it reads, so .Any() removes the first item, and the method then returns the rest.

The fix takes the first item with TryTake, and returns it before the rest. I have this fix with tests, and I can open a pull request.

Reproducing the Problem

Run the decorator on a canonical future, with a stub IDataDownloader that returns the same 3 minute bars for each of 2 contracts, then compare the returned bars with the bars the stub produced.

On master at 6f30bf499, this test fails. The first bar of 1 contract is missing:

Expected: equivalent to < "MNQ YYFADOG4CO3L 2025-12-08T00:00:00.0000000", "MNQ YYFADOG4CO3L 2025-12-08T00:01:00.0000000", "MNQ YYFADOG4CO3L 2025-12-08T00:02:00.0000000", ...
But was:  < "MNQ YYFADOG4CO3L 2025-12-08T00:01:00.0000000", "MNQ YYFADOG4CO3L 2025-12-08T00:02:00.0000000", "MNQ Z3EHQP0U9ZB5 2025-12-08T00:00:00.0000000", ...

With the fix, all 31 tests in CanonicalDataDownloaderDecoratorTests pass. I also saw the loss in real downloads: each lean data download of a future root through the DataBento module lost 1 bar.

System Information

Windows 11, .NET SDK 10.0.403, master at 6f30bf499.

Checklist

  • I have completely filled out this template
  • I have confirmed that this issue exists on the current master branch
  • I have confirmed that this is not a duplicate issue by searching issues
  • I have provided detailed steps to reproduce the issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions