Skip to content

Canonical option downloads discard the first history point #22

Closed

Description

Problem

ThetaDataDownloader.GetCanonicalOptionHistory drops the first history point produced for every non-empty canonical option download.

At ThetaDataDownloader.cs:119–127, options is a BlockingCollection<BaseData>.GetConsumingEnumerable(). Calling options.Any() removes its first item. Returning options then delivers only the remaining points. The discarded contract/time can vary because the history requests run in parallel. If just one point is produced, the result is non-null but empty.

Reproduction

The consuming-probe logic reproduces without an account or network requests:

using var queue = new BlockingCollection<int>();
queue.Add(1);
queue.Add(2);
queue.CompleteAdding();
var data = queue.GetConsumingEnumerable();
Console.WriteLine(data.Any());                // True; consumes 1
Console.WriteLine(string.Join(",", data));   // 2, not 1,2

I ran this pattern with 1, 2 and 6 queued items: the returned sequence contained 0, 1 and 5 items respectively. The production path above uses the same probe on BaseData; no ThetaData request was run.

Expected outcome

Return every history point produced, while retaining null for an entirely empty response. A suggested fix is to retain the first point taken while waiting for data and yield it before the remaining stream. Add no-data, single-point and multi-contract regression tests.

Activity

  1. Martin-Molinero commented on Nov 12, 2026

    @Martin-Molinero
    Member

    QuantConnect/Lean#10100 adds a shared helper for this: GetConsumingEnumerableOrNull() on a BlockingCollection<T> waits for the first item, returns null if the collection completes adding without one, and otherwise returns every item, the first one included. Once this repository builds against a Lean that has it, the fix is one call:

    return blockingOptionCollection.GetConsumingEnumerableOrNull();

    It replaces the GetConsumingEnumerable() + Any() check and keeps returning null when nothing was added.

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