EquityBhav.py — Equity Classes
Contains three classes that handle equity EOD data, index data, and delivery volumes.
Class Relationships
NseEodEqUpdater
Handles equity bhav copy download and DB ingestion.
update()
Main entry — iterates through all missing NSE working days and processes each.
update_a_day(mdate, mdelfile, updateonly=False) → bool
Downloads and ingests equity data for a single date.
- Downloads bhav copy ZIP (new or old format via
NseDownLoaderorutils) - Downloads index CSV (via
NseEodIndexUpdater.downloadbhav) - Deletes existing row for that date from
scr_nseeq_eod - Calls
utils.new_process_and_update_EqBhav()orutils.process_and_update_EqBhav() - Moves processed file to
BhavCopies/updated/
Task Tracking (typ=2)
Failed downloads are stored in the tasks table as JSON:
{
"2026-05-20": {"retries": 1, "lasttry": "2026-05-21"},
"2026-05-21": {"retries": 0, "lasttry": "2026-05-21"}
}
repair()
Retries all pending failed download tasks. Removes successfully processed ones.
NseEodIndexUpdater
Downloads and ingests NSE index data (ind_close_all_DDMMYYYY.csv).
downloadbhav(mdate) → bool
Downloads index snapshot from niftyindices.com. If download fails,
queues it in the tasks table (typ=1) for retry.
update(mdate, updateonly=False)
- Downloads the index CSV (unless
updateonly=True) - Calls
utils.updateindexbhav()which:- Merges with
Indexinfo.csvfor standardised index names - Inserts new symbols into
scr_masterif needed - Writes OHLCV to
scr_nseeq_eod(indices share the same table as equities) - Writes PE/PB to
scr_indexpepb - Moves processed file to
BhavCopies/updated/
- Merges with
NseEodDelValDownloader
Downloads delivery volume files (MTO_DDMMYYYY.DAT).
downloadbhav(mDate) → str
Downloads MTO_DDMMYYYY.DAT from NSE archives if not already present.
Returns the filename string (or empty string on failure).
Delivery data is merged into equity rows as the delqty column.
NSE File URL Patterns
| File type | URL pattern |
|---|---|
| Equity bhav (new) | https://nsearchives.nseindia.com/content/cm/BhavCopy_NSE_CM_0_0_0_YYYYMMDD_F_0000.csv.zip |
| Equity bhav (old) | https://archives.nseindia.com/content/historical/EQUITIES/YYYY/MON/cmDDMONYYYYbhav.csv.zip |
| Index snapshot | https://www.niftyindices.com/Daily_Snapshot/ind_close_all_DDMMYYYY.csv |
| Delivery volume | https://archives.nseindia.com/archives/equities/mto/MTO_DDMMYYYY.DAT |
| F&O bhav (new) | https://nsearchives.nseindia.com/content/fo/BhavCopy_NSE_FO_0_0_0_YYYYMMDD_F_0000.csv.zip |
| F&O bhav (old) | https://archives.nseindia.com/content/historical/DERIVATIVES/YYYY/MON/foDDMONYYYYbhav.csv.zip |