Fix bhavcopy returning legacy format for historical UDiFF dates - #133
Merged
Conversation
The daily-reports API only serves the last two trading days, so for any
UDiFF-era date older than that, bhavcopy_raw silently fell back to the
legacy 15-column BHAVDATA-FULL format. Add bhavcopy_udiff_raw, which
fetches the 34-column UDiFF archive NSE serves at
/content/cm/BhavCopy_NSE_CM_0_0_0_{YYYYMMDD}_F_0000.csv.zip for all
dates from Jul 2024 onward. The daily-reports API and legacy fallback
are kept as backups.
💘 Generated with Crush
Assisted-by: Crush:deepseek-v4-flash
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.
Summary
bhavcopy_raw()silently returned the legacy 15-column BHAVDATA-FULL format for any UDiFF-era date (>= 2024-07-08) older than the last two trading days. The daily-reports API it used only serves the current and previous trading day, and the failure was swallowed by a bareexcept ... passfallback.Changes
bhavcopy_udiff_raw()which fetches the 34-column UDiFF archive NSE serves at/content/cm/BhavCopy_NSE_CM_0_0_0_{YYYYMMDD}_F_0000.csv.zip— verified working for all dates from 2024-07-05 onward (the old/content/historical/EQUITIES/...route suggested previously now 404s for everything).bhavcopy_raw()now tries, in order: historical UDiFF archive (with aTradDtheader check) → daily-reports API → legacy BHAVDATA-FULL fallback.test_bhavcopy_recent, whose"ISIN" in rassertion passed vacuously (it matchedBALKRISINDin the legacy data), and added a regression test for a historical UDiFF date (2025-07-21).Testing
Full suite passes: 67 passed (including live network tests), and the fix verified against the original bug report's example.
💘 Generated with Crush