Skip to content

fix(options): retry fetching expirations on missing date (#469) - #2968

Open
dwaddle wants to merge 2 commits into
ranaroussi:mainfrom
dwaddle:fix-option-expiration-retry
Open

dwaddle wants to merge 2 commits into
ranaroussi:mainfrom
dwaddle:fix-option-expiration-retry

Conversation

@dwaddle

@dwaddle dwaddle commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Describe your changes

This PR fixes a well-known stability issue with the options module where the Yahoo Finance

API occasionally desyncs, resulting in a random ValueError: Expiration ... cannot be found.

**The Problem:**
When requesting an option chain for a specific date, the date may occasionally be missing

from the cached self._expirations dictionary due to transient API desyncs. This previously
caused automated trading loops to crash abruptly, even if the expiration date was completely
valid.

The Solution:
Instead of immediately throwing a ValueError when 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.

This simple change significantly increases the robustness of the options module for automated

and quantitative traders.

### Related Issue
Closes #469

### Checklist
- [x] I have tested my changes locally.
- [x] The code follows the project's formatting guidelines.

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant