from datetime import timedelta, date
from nsepy import get_history
def importdata(stock):
stock_fut = get_history(symbol=stock,
start=date.today() - timedelta(days = 15), end=date.today(),
futures=True,
expiry_date=date(2022,7,28))
print(stock_fut[["Underlying","Change in OI","Open Interest"]])
a = ["MARUTI","HEROMOTOCO","BAJAJ-AUTO","M&M","EICHERMOT"]
for i in range(0,len(a)):
print(a[i])
importdata(a[i])
Now I want only last 10 days historical data. So I need to change the timedelta value regularly.What will be the code for start date and end date so that it always give me only 10 days data without need of changing timedelta value. In other words it takes input of 10 days always excluding Saturday, Sunday and other trading holidays.
source https://stackoverflow.com/questions/73093571/how-to-avoid-trading-holidays-during-historical-data
Comments
Post a Comment