I am encountering the following error while running my strategies. Currently, I am using the same API token for all strategies. Will this issue be resolved if I use separate tokens for each strategy?
How many parallel threads or concurrent requests does Dhan allow per token? Additionally, if the requests are different in nature—for example, one request to retrieve historical data and another to fetch the option chain—will this error still occur?
Error: TooManyRequests: 429 Too Many Requests: {"data":{"805":"Too many requests. Further requests may result in the user being blocked."},"status":"failed"}
You have to structure the code to not poll certain endpoints too much, for example quote route accepts only 1 req/s which is standard among all the major brokers but it also allows you to get all the instruments you want so there’s really no need to poll it more than once per second.
The rate limits for each route is described in the docs:
@pavinjoseph , Thanks for your advice. I added the common option chain and LTP fetching code in a synchronized block and added 1 second sleep time. The issue is resolved now.
I will implement caching also.