Rate limiting for APIs

Hi, I am trying to run a simple code where I am trying to print ATM Strike details for nifty and later on print the OTM strike details for nifty.
I have observed that if I don’t add time.sleep() between two API calls, I am getting the below error

Screenshot 2026-07-26 at 6.21.50 PM

Question: Is time.sleep(ms) mandatory?
What is the alternative?
FYI : I am using Dhan Tradehull.
Should I use Dhanhq or higher performance?

My sample code

”””
atm_call_name, atm_put_name, atm_strike = tsl.ATM_Strike_Selection(Underlying=‘NIFTY’, Expiry=0)

print(“ATM Strike Details: “, atm_call_name,”\t” ,atm_put_name,“\t” , atm_strike)

# Add delay between API calls to avoid rate limiting

# time.sleep(1)

otm_call_name, otm_put_name, otm_call_strike, otm_put_strike = tsl.OTM_Strike_Selection(Underlying=‘NIFTY’, Expiry=0, OTM_count=5)

print(“OTM Strike Details: “, otm_call_name,”\t” ,otm_put_name,“\t” , otm_call_strike,“\t” , otm_put_strike)
”””

Hi @Neil_Shah ,

Yes, at least 1 second should be maintained between consecutive API calls. If the next API request is made before 1 second, it may fail due to the API rate limit. Therefore, it is recommended to use “time.sleep(1)” between consecutive API calls.

1 Like