Skip to content

Fix bhavcopy returning legacy format for historical UDiFF dates - #133

Merged
sevakram merged 1 commit into
masterfrom
fix/udiff-historical-bhavcopy
Aug 21, 2026
Merged

Fix bhavcopy returning legacy format for historical UDiFF dates#133
sevakram merged 1 commit into
masterfrom
fix/udiff-historical-bhavcopy

Conversation

@swapniljariwala

Copy link
Copy Markdown
Contributor

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 bare except ... pass fallback.

Changes

  • Added 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 a TradDt header check) → daily-reports API → legacy BHAVDATA-FULL fallback.
  • Fixed test_bhavcopy_recent, whose "ISIN" in r assertion passed vacuously (it matched BALKRISIND in 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

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
@sevakram
sevakram merged commit e11a881 into master Aug 21, 2026
2 checks passed
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