From 86ad08492acdf52c5fce33f1383f944629dcacfb Mon Sep 17 00:00:00 2001 From: kgoenka Date: Fri, 21 Jun 2024 22:35:37 -0500 Subject: [PATCH 1/2] add ability to save UDiFF format for cm and fo --- jugaad_data/nse/archives.py | 50 ++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/jugaad_data/nse/archives.py b/jugaad_data/nse/archives.py index ce6bd33..3bc59fb 100644 --- a/jugaad_data/nse/archives.py +++ b/jugaad_data/nse/archives.py @@ -48,7 +48,10 @@ def __init__(self): "bhavcopy": "/content/historical/EQUITIES/{yyyy}/{MMM}/cm{dd}{MMM}{yyyy}bhav.csv.zip", "bhavcopy_full": "/products/content/sec_bhavdata_full_{dd}{mm}{yyyy}.csv", "bulk_deals": "/content/equities/bulk.csv", - "bhavcopy_fo": "/content/historical/DERIVATIVES/{yyyy}/{MMM}/fo{dd}{MMM}{yyyy}bhav.csv.zip" + "bhavcopy_fo": "/content/historical/DERIVATIVES/{yyyy}/{MMM}/fo{dd}{MMM}{yyyy}bhav.csv.zip", + "udiff_bhavcopy":"/content/cm/BhavCopy_NSE_CM_0_0_0_{yyyy}{mm}{dd}_F_0000.csv.zip", + "udiff_bhavcopy_fo":"/content/fo/BhavCopy_NSE_FO_0_0_0_{yyyy}{mm}{dd}_F_0000.csv.zip", + } def get(self, rout, **params): @@ -133,6 +136,46 @@ def bhavcopy_fo_save(self, dt, dest, skip_if_present=True): with open(fname, 'w') as fp: fp.write(text) return fname + + @unzip + def udiff_bhavcopy_fo_raw(self, dt): + """Downloads raw bhavcopy text for a specific date""" + dd = dt.strftime('%d') + mm = dt.strftime('%m').upper() + yyyy = dt.year + r = self.get("udiff_bhavcopy_fo", yyyy=yyyy, mm=mm, dd=dd) + return r.content + + def udiff_bhavcopy_fo_save(self, dt, dest, skip_if_present=True): + """ Saves Derivatives Bhavcopy to a directory """ + fmt = "BhavCopy_NSE_FO_0_0_0_%Y%m%d_F_0000.csv" + fname = os.path.join(dest, dt.strftime(fmt)) + if os.path.isfile(fname) and skip_if_present: + return fname + text = self.udiff_bhavcopy_fo_raw(dt) + with open(fname, 'w') as fp: + fp.write(text) + return fname + + @unzip + def udiff_bhavcopy_raw(self, dt): + """Downloads raw bhavcopy text for a specific date""" + dd = dt.strftime('%d') + mm = dt.strftime('%m').upper() + yyyy = dt.year + r = self.get("udiff_bhavcopy", yyyy=yyyy, mm=mm, dd=dd) + return r.content + + def udiff_bhavcopy_save(self, dt, dest, skip_if_present=True): + """ Saves Derivatives Bhavcopy to a directory """ + fmt = "BhavCopy_NSE_FO_0_0_0_%Y%m%d_F_0000.csv" + fname = os.path.join(dest, dt.strftime(fmt)) + if os.path.isfile(fname) and skip_if_present: + return fname + text = self.udiff_bhavcopy_raw(dt) + with open(fname, 'w') as fp: + fp.write(text) + return fname class NSEIndicesArchives(NSEArchives): def __init__(self): @@ -181,6 +224,11 @@ def bhavcopy_index_save(self, dt, dest, skip_if_present=True): full_bhavcopy_save = a.full_bhavcopy_save bhavcopy_fo_raw = a.bhavcopy_fo_raw bhavcopy_fo_save = a.bhavcopy_fo_save +udiff_bhavcopy_fo_raw = a.udiff_bhavcopy_fo_raw +udiff_bhavcopy_fo_save = a.udiff_bhavcopy_fo_save +udiff_bhavcopy_raw = a.udiff_bhavcopy_raw +udiff_bhavcopy_save = a.udiff_bhavcopy_save + ia = NSEIndicesArchives() bhavcopy_index_raw = ia.bhavcopy_index_raw bhavcopy_index_save = ia.bhavcopy_index_save From fc4ccc6f472a17996dc772336a8166a01ceba657 Mon Sep 17 00:00:00 2001 From: Kushal Goenka Date: Sat, 13 Jul 2024 22:57:16 -0500 Subject: [PATCH 2/2] Update jugaad_data/nse/archives.py fix: saved file name for cm Co-authored-by: Sahil Shah <53784576+sahilshah6196@users.noreply.github.com> --- jugaad_data/nse/archives.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jugaad_data/nse/archives.py b/jugaad_data/nse/archives.py index 3bc59fb..cdd4bff 100644 --- a/jugaad_data/nse/archives.py +++ b/jugaad_data/nse/archives.py @@ -168,7 +168,7 @@ def udiff_bhavcopy_raw(self, dt): def udiff_bhavcopy_save(self, dt, dest, skip_if_present=True): """ Saves Derivatives Bhavcopy to a directory """ - fmt = "BhavCopy_NSE_FO_0_0_0_%Y%m%d_F_0000.csv" + fmt = "BhavCopy_NSE_CM_0_0_0_%Y%m%d_F_0000.csv" fname = os.path.join(dest, dt.strftime(fmt)) if os.path.isfile(fname) and skip_if_present: return fname