Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to save UDiFF format for cm and fo #80

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion jugaad_data/nse/archives.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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_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
text = self.udiff_bhavcopy_raw(dt)
with open(fname, 'w') as fp:
fp.write(text)
return fname

class NSEIndicesArchives(NSEArchives):
def __init__(self):
Expand Down Expand Up @@ -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
Expand Down