Hi everyone,
I'm working with my broker's historical data API to retrieve a year's worth of 1-minute data for Indian stocks. The API documentation states that I should be able to fetch 30 days' worth of 1-minute data per request, but it only returns the last 2,000 records. I have attempted to contact their support team regarding this issue, but it's been over a week, and I haven't received a reply.
Thus, I've implemented a method that iteratively fetches 2,000 records per request by moving backward from the current date, aiming to accumulate a year's worth of data. This should total exactly 92,250 records. However, my script is only able to fetch 92,000 records. Here are the last few lines of the output:
...
Fetched 2000 records starting at 2023-09-04 10:55:00 and ending at 2023-09-11 12:59:00
Fetched 2000 records starting at 2023-08-25 15:05:00 and ending at 2023-09-04 10:54:00
Fetched 2000 records starting at 2023-08-18 13:00:00 and ending at 2023-08-25 15:04:00
Fetched 2000 records starting at 2023-08-10 10:55:00 and ending at 2023-08-18 12:59:00
Total fetched records: 92000
As you can see, the last request ends at 12:59, whereas the Indian stock market stays open from 9:15 AM to 3:30 PM. I believe that this timing discrepancy might be causing the data to fall short by 250 records.
Could anyone suggest a way to make my script keep fetching data until the market closes while not exceeding the 2,000 records per request limit?
Here’s my script(note: it requires API credentials, so it won't run without them):