Skip to content

Comments

Feat: CanonicalDataDownloaderDecorator for chain support#9299

Merged
Romazes merged 23 commits intoQuantConnect:masterfrom
Romazes:refactor-canonical-downloader-handler
Feb 23, 2026
Merged

Feat: CanonicalDataDownloaderDecorator for chain support#9299
Romazes merged 23 commits intoQuantConnect:masterfrom
Romazes:refactor-canonical-downloader-handler

Conversation

@Romazes
Copy link
Collaborator

@Romazes Romazes commented Feb 17, 2026

Description

The PR added the CanonicalDataDownloaderDecorator, which helps to download/research/backtest data for Option, FutureOption, IndexOption and Future, read the universes file, and select the available contracts for a specific date range in the algorithm using a specific DataSource provider (e.g. DataBento, Polygon, ...).

In addition:
Added the TryAdjustDateRangeForContract helper static method, which can be used externally in any DataProvider to improve the speed of downloading security types with expiry opportunities.

Related Issue

Actually, it relates to the DataBento repo to use it comfortably in backtesting mode.

Motivation and Context

Utilizes the Lean engine flexibly with generic logic applied universally across all plugins.

Requires Documentation Change

N/a

How Has This Been Tested?

  • lean data download --data-provider-historical databento --data-type Trade --resolution Daily --security-type Future --market CME --ticker ES --start 20260201 --end 20260210

    • universe unavailable
    image
    • universe available
      • data was download successfully and keep on disk
    image
  • lean data download --data-provider-historical databento --data-type Trade --resolution minute --security-type Future --market CME --ticker ES --start 20260201 --end 20260210 (minute)

image
  • lean backtest DatabentoTestAlgo --data-provider-historical DataBento (Daily)
var sp = AddFuture(QuantConnect.Securities.Futures.Indices.SP500EMini, Resolution.Daily);
sp.SetFilter(x => x.Expiration(0, 120));
image
  • lean backtest DatabentoTestAlgo --data-provider-historical DataBento (Minute)
var sp = AddFuture(QuantConnect.Securities.Futures.Indices.SP500EMini, Resolution.Minute);
sp.SetFilter(x => x.Expiration(0, 120));
image
  • lean data download --data-provider-historical Polygon --market USA --data-type trade --security-type Option --ticker AAPL --resolution minute --start 20260201 --end 20260210 (I have used custom Polygon pckg without support Canonical symbols)
image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which improves implementation)
  • Performance (non-breaking change which improves performance. Please add associated performance test and results)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Non-functional change (xml comments/documentation/etc)

Checklist:

  • My code follows the code style of this project.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My branch follows the naming convention bug-<issue#>-<description> or feature-<issue#>-<description>

Copy link
Member

@Martin-Molinero Martin-Molinero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Copy link
Member

@Martin-Molinero Martin-Molinero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@Romazes Romazes force-pushed the refactor-canonical-downloader-handler branch from f80b87f to 1a17a50 Compare February 20, 2026 18:26
Introduced CanonicalDataDownloaderDecorator to enable automatic resolution and parallel downloading of all contracts for canonical symbols (options and futures chains). Updated Program.cs and DownloaderDataProvider to use this decorator, ensuring seamless data retrieval for both canonical and non-canonical symbols. Refactored initialization logic to handle chain providers within the decorator and removed redundant code from Program.cs.
Introduce DataDownloaderSelector to choose the correct IDataDownloader implementation based on data type, using CanonicalDataDownloaderDecorator only when needed. Update Program.cs and DownloaderDataProvider to use the selector, remove redundant initialization logic, and ensure proper resource disposal. This improves flexibility, correctness, and resource management for data downloads, especially for custom and canonical data types.
…oader

- Set ConsoleLogHandler as the default log handler in code and config
- Make contract download parallelism configurable via downloader-thread-count (default 4)
- Track and log number of processed contracts in CanonicalDataDownloaderDecorator
- Add error logging for missing universe data
- Improve logging clarity and code readability
Introduce ContractDownloadParameters to uniquely identify contract/tick type/resolution combinations and cache them in CanonicalDataDownloaderDecorator, avoiding redundant downloads when contracts are shared across canonical symbol chains. Add date range optimization for contract downloads and unit tests for the new class.
Added AdjustDateRangeForContract to CanonicalDataDownloaderDecorator to clamp start/end dates based on contract expiry and security type. Introduced _contractsCache to prevent duplicate downloads across canonical chains and _processedContracts for logging. Updated contract retrieval logic for deduplication. Added NUnit tests to verify date range adjustments for futures and options.
Revert "refactor: remove Lazy from CanonicalDataDownloaderDecorator"

This reverts commit 909c129.

refactor: Inject IMapFileProvider into downloader selectors

Revert "refactor: Inject IMapFileProvider into downloader selectors"

This reverts commit 0add952.

Reapply "refactor: remove Lazy from CanonicalDataDownloaderDecorator"

This reverts commit 9e3c4be.
@Romazes Romazes force-pushed the refactor-canonical-downloader-handler branch from 064c71c to ea5384e Compare February 23, 2026 12:12
- Require explicit IDataProvider in DataDownloaderSelector constructor, removing default and fallback logic
- Change default log handler to ConsoleLogHandler in Program.cs
- Pass DownloaderDataProvider as IDataProvider to DataDownloaderSelector
- Add DataDownloaderSelector unit tests to verify correct downloader selection and decorator usage
@Romazes Romazes merged commit d1337ea into QuantConnect:master Feb 23, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants