Repository navigation
Conversation
Yahoo's backend API occasionally desyncs, resulting in empty or outdated expiration dates and a ValueError when fetching a valid option chain. We now force a cache refresh (_download_options) before throwing the exception.
This branch has not been deployed
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.
Describe your changes
API occasionally desyncs, resulting in a random
ValueError: Expiration ... cannot be found.from the cached
self._expirationsdictionary due to transient API desyncs. This previouslycaused automated trading loops to crash abruptly, even if the expiration date was completely
valid.
The Solution:
Instead of immediately throwing a
ValueErrorwhen a requested expiration date is missing,the
option_chain()function now forces a single cache refresh (self._download_options()).- If the API recovers and provides the date, the chain is returned normally.
- If the date is still missing after the retry, the code falls back to the standard
ValueError.and quantitative traders.