Too many request error

Unbreakable
Hi I have written the below code to get 100 days daily candle details of any stock. I am getting an error saying that too many requests. I know that the error is because I am breaking the API limits . Can any one help me to get the desired result without breaking the API limit.

def Export_Entire_Data(from_date, symbol,instrument):
data = pd.DataFrame(columns=['Date', 'Open', 'High', 'Low', 'Close', 'Volume'])
days = 100
interval = 'day'
k=0
entry = 0

while entry<days:
try:
tt__=pd.DataFrame()
tt__.iloc[0:0]
tt__=pd.DataFrame(kite.historical_data(instrument,from_date,from_date,interval))
tt_= tt__.head(1)
data.loc[k,"Date"] = tt_.loc[0, "date"]
data.loc[k,"Open"] = tt_.loc[0, "open"]
data.loc[k,"High"] = tt_.loc[0, "high"]
data.loc[k,"Low"] = tt_.loc[0, "low"]
data.loc[k,"Close"] = tt_.loc[0, "close"]
data.loc[k,"Volume"] = tt_.loc[0, "volume"]
from_date = from_date-timedelta(days=1)
k=k+1
entry=entry+1
except:
time.sleep(1)

#data.set_index("date",inplace=True)
return data


testdate = dt.datetime(2024, 1, 5)
Test_Token = df[df.tradingsymbol == "INFY"].index[0]
Hd_DF = Export_Entire_Data(testdate,"INFY",Test_Token)
print(Hd_DF)

Tagged:
Sign In or Register to comment.