This might reduce some effort of downloading csv and changing dates
Edit-Forgot Holidays now must work fine
still needs to consider if two holiday are together except SAT,SUN maybe creating local file having holiday dates was less messy
Python:
import os.path
import requests,zipfile,io
import datetime
today = datetime.date.today()
yesterday = today - datetime.timedelta(days = 10)
PREVDAY=yesterday.strftime("%a")
if PREVDAY=='Sun':
yesterday -= datetime.timedelta(days = 2)
DATE=yesterday.strftime("%d%b%Y").upper()
YEAR=yesterday.strftime("%Y")
MON=yesterday.strftime('%b').upper()
LINK= f"https://www.nseindia.com/content/historical/EQUITIES/{YEAR}/{MON}/cm{DATE}bhav.csv.zip"
print(f'Downloading -{DATE} csv')
r = requests.get(LINK)
if len(r.content)<300:
print('Yesterday was holiday')
yesterday -= datetime.timedelta(days = 1)
DATE=yesterday.strftime("%d%b%Y").upper()
YEAR=yesterday.strftime("%Y")
MON=yesterday.strftime('%b').upper()
LINK=f"https://www.nseindia.com/content/historical/EQUITIES/{YEAR}/{MON}/cm{DATE}bhav.csv.zip"
r = requests.get(LINK)
z = zipfile.ZipFile(io.BytesIO(r.content))
z.extractall(path='C:\\tradingsystem\\data')
print (f"Check if ORDERFILE {DATE} date is correct, File downloaded")
else:
z = zipfile.ZipFile(io.BytesIO(r.content))
z.extractall(path='C:\\tradingsystem\\data')
print ("File downloaded")
ORDER_FILENAME = f'data/cm{DATE}bhav.csv'