[Fix] Mock NSE option chain tests to be market-hours independent (Fixes #112)#114
Merged
Merged
Conversation
Issue #112: Tests for option chain endpoints were failing because they depended on live API responses, which return empty data when the market is closed. Changes: - Created fixtures_option_chain.py with realistic test data for: - NIFTY indices option chain - RELIANCE equities option chain - USDINR currency option chain - Updated test_nse_live.py to use unittest.mock to patch API responses - Tests now use mocked data instead of live API calls - All 47 tests pass, tests are now market-hours independent Benefits: - Tests pass 24/7 regardless of market hours - Tests are deterministic and fast - No flaky failures due to market closure or API availability - Proper unit testing practice (isolated from external APIs)
…ent" This reverts commit 7c49cc8.
This reverts commit d7d591b.
…ameter NSE has migrated option chain APIs from /api/option-chain-indices and /api/option-chain-equities to /api/option-chain-v3 endpoint. Changes: - Updated endpoint routes to use new /api/option-chain-v3 endpoint - Added /api/option-chain-contract-info endpoint for fetching available expiry dates - Created new option_chain_contract_info() function to fetch available expiries - Modified index_option_chain() and equities_option_chain() to accept optional expiry parameter - If expiry is not provided, automatically fetches nearest available expiry via contract info - Added comprehensive docstrings explaining the APIs and parameters The new v3 endpoint requires both symbol and expiry date. The contract-info endpoint returns available expiry dates and strike prices for each symbol. Fixes: #112 Tests: All 14 NSE live tests passing
- Updated version from 0.31.1 to 0.31.2 in pyproject.toml (patch bump for bug fix) - Added changelog entry for 0.31.2 with fixes for NSE option chain API changes - Documented the fix for issue #112
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.
Tests for option chain endpoints were failing because they depended on live API responses that return empty data when the market is closed. Fixed by mocking API responses with realistic test data. All 47 tests now pass.