Getting "Too many requests" exception while fetching historical data.

anujkk
This is my first post here. My code was running fine till yesterday. I understand that there is an API rate limit of 3req/second for historical candle. To prevent that I am using time.sleep(1) after each request. I am also handling the exception by using time.sleep(1) and retrying after one second. However, the exception is still getting raised and it takes around 60 retries to resume the processing. Any idea why this is happening?

while True:
try:
if from_date.date() >= (dt.date.today() - dt.timedelta(duration)):
data = data.append(pd.DataFrame(kite.historical_data(instrument, from_date, dt.date.today(), interval)), ignore_index=True)
time.sleep(1)
break
else:
to_date = from_date + dt.timedelta(duration)
data = data.append(pd.DataFrame(kite.historical_data(instrument, from_date, to_date, interval)), ignore_index=True)
time.sleep(1)
from_date = to_date
break
except kite_exceptions.DataException as e:
print("Caught DataException:", e)
print("Retrying after 1 second...")
time.sleep(1)
continue
Sign In or Register to comment.