Skip to content

[Fix] Mock NSE option chain tests to be market-hours independent (Fixes #112)#114

Merged
sevakram merged 6 commits into
masterfrom
fix/issue-112-nse-option-chain-empty-response
Mar 16, 2026
Merged

[Fix] Mock NSE option chain tests to be market-hours independent (Fixes #112)#114
sevakram merged 6 commits into
masterfrom
fix/issue-112-nse-option-chain-empty-response

Conversation

@sevakram
Copy link
Copy Markdown
Contributor

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.

abc-git added 5 commits March 14, 2026 14:25
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)
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
@sevakram sevakram merged commit 684b64f into master Mar 16, 2026
2 checks passed
- 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
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.

2 participants