Nifty50 Index Historical data for current_day is taking 7s to return data

chethanthewarrior
I have the following code snippet for fetching historical data in real-time. And I observe that for Nifty 50 Index, it is taking up to 7s to return data which is huge.

from_date = datetime.today().date().strftime('%Y-%m-%d')
to_date = datetime.today().date().strftime('%Y-%m-%d')

print("Time when current_data is called", datetime.now().time(), flush=True)
calling_time = datetime.now()
current_data = kite.historical_data(256265, from_date, to_date, '5minute')
print("Time when current_data is returned", datetime.now().time(), flush=True)
returning_time = datetime.now()
print("Time taken", (returning_time - calling_time))

And the O/P after running in loop for 10 times is

Time when current_data is called 13:12:40.941164
Time when current_data is returned 13:12:48.512981
Time taken 0:00:07.571817
Time when current_data is called 13:12:48.512981
Time when current_data is returned 13:12:56.144059
Time taken 0:00:07.631078
Time when current_data is called 13:12:56.144059
Time when current_data is returned 13:13:03.663743
Time taken 0:00:07.519684
Time when current_data is called 13:13:03.663743
Time when current_data is returned 13:13:11.158077
Time taken 0:00:07.494334
Time when current_data is called 13:13:11.158077
Time when current_data is returned 13:13:18.603435
Time taken 0:00:07.445358
Time when current_data is called 13:13:18.603435
Time when current_data is returned 13:13:26.513466
Time taken 0:00:07.910031
Time when current_data is called 13:13:26.513466
Time when current_data is returned 13:13:33.972632
Time taken 0:00:07.459166
Time when current_data is called 13:13:33.972632
Time when current_data is returned 13:13:41.366290
Time taken 0:00:07.393658
Time when current_data is called 13:13:41.366290
Time when current_data is returned 13:13:48.761259
Time taken 0:00:07.394969
Time when current_data is called 13:13:48.761259
Time when current_data is returned 13:13:49.370916
Time taken 0:00:00.609657

why so much time is taken for API to return data?
  • rakeshr
    Historical data is provided for backtesting purposes only. It is not meant for live strategies. You can go through this thread to know more.
Sign In or Register to comment.