Delay reading option chain universe files until close to market open in live trading - #9690
Draft
jhonabreul wants to merge 1 commit into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In live trading, option chain universes are backed by the daily universe files under
Data/option/<market>/universes/. The file for the previous tradable date is read at deployment time and then re-read on every refresh cycle (every 10 minutes) around the clock, even though a new file only appears once per day. Option chain universe files can be big, so this is wasted IO, and reads during the night overlap with the window in which the data pipeline is still writing the new files.The change:
LiveCustomDataSubscriptionEnumeratorFactoryaccepts an optionalcanRefreshpredicate: while it returns false the source is not refreshed or read. The predicate is evaluated at the same cadence as source refreshes, so it is rate limited as well.LiveTradingDataFeed.CreateUniverseSubscriptionpasses a gate forOptionChainUniversesubscriptions (GetUniverseFileRefreshGate): the universe file is only read while the exchange is open or within one hour of the next market open (PreOpenUniverseFileRefreshWindow).Behavioral effect: for an algorithm deployed while the market is closed, option chain selection now happens between one hour before market open and the open, instead of right at deployment.
Related Issue
N/A
Motivation and Context
Option chain universe files are among the biggest files Lean reads in live trading; reading them around the clock, including overnight while the new files are still being generated, wastes IO for no benefit. Delaying the read until shortly before the market opens ensures the file is read when it is complete and about to be needed.
Requires Documentation Change
No
How Has This Been Tested?
LiveCustomDataSubscriptionEnumeratorFactoryTests.RespectsRefreshGate: with the gate closed the source is never read regardless of time passing; gate checks are rate limited like refreshes; once the gate opens the next refresh reads the source.LiveTradingDataFeedTests.OptionChainSelectionIsDelayedUntilCloseToMarketOpen(equity option and index option cases): algorithm deployed at 2 am, asserts the first chain selection happens within [market open - 1 hour, market open]. Red before the change (selection happened right at deployment), green after.LiveTradingDataFeedTestsandLiveCustomDataSubscriptionEnumeratorFactoryTestsfixtures with CI category filters: 195 passed, 0 failed, 1 skipped (pre-existing ignored test).FakeDataQueue, temporary test-only time provider offset shifting the engine clock to 8:13 am ET pre-open, with a fabricated GOOG universe file for the previous tradable date): the universe refresh gate was checked and blocked at 8:13 and 8:23, and the file was read and the option filter invoked at 8:33 am ET — inside the one hour pre-open window — selecting all 2192 contracts, with zero errors in the log. The instrumentation was discarded after the run.Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>