startdate = datetime.date(2018,1,1)
expirydate = datetime.date(2018,1,4)
data = dict()
for x in range(0,3):
for y in range(1,8):
data [y] = get_history(symbol="BANKNIFTY",
start= startdate,
end= startdate,
index=True,
option_type='CE',
strike_price= 27000,
expiry_date=expirydate)
startdate += datetime.timedelta(days=1)
expirydate += datetime.timedelta(days=7)
The loop works well but only gives me last set of values i.e. when x = 3. Rest all previous values gets overridden.
You are going to have to differentiate the different
yvalues from the ones in the previous loops ofxvalues. For instance you can setdata[(x, y)]instead ofdata[y]. To avoid adding empty values, just add the conditional to check for a value before setting it to your dictionary: