I’m trying to get the option chain data of 2 different expiry and I get the “429 too many requests” error. Why is the 3 second rate limiting applied for different expiry?
I’m aware of the rate limiting - 5 reqs/s for data APIs and for option chain API, it is 1 req per 3 sec (because OI data gets updated slow) as per docs.
If the intention is to rate limit because data updates are slow, allow to fetch other expiry data within the global data API rate limit of 5 reqs/s. The current one doesn’t even allow 2!?
Am I doing this wrong or it is what it is? Is there any workaround?
Code:
async def fetch_oc_data(db, client, instrument):
expiries = await fetch_expiries(client, instrument)
print(f"Got {len(expiries)} expiries for {instrument['SECURITY_ID']}")
for i, expiry in enumerate(expiries):
try:
print(f"Fetching {instrument['SECURITY_ID']} {expiry} ({i+1}/{len(expiries)})")
oc, last_price = await fetch_chain_for_expiry(client, instrument, expiry)
store_oc_data(db, instrument, expiry, oc)
print(f"Successfully stored {instrument['SECURITY_ID']} {expiry}")
except Exception as e:
print(f"Error fetching {instrument['SECURITY_ID']} {expiry}: {e}")
continue
db.commit()
print("added all expiry oc data to db")
Console:
Got 18 expiries for NIFTY
Fetching NIFTY 2025-06-19 (1/18)
Successfully stored NIFTY 2025-06-19
Fetching NIFTY 2025-06-26 (2/18)
Error fetching NIFTY 2025-06-26: Client error '429 Too Many Requests' for url 'https://api.dhan.co/v2/optionchain'
Fetching NIFTY 2025-07-03 (3/18)
Error fetching NIFTY 2025-07-03: Client error '429 Too Many Requests' for url 'https://api.dhan.co/v2/optionchain'
Fetching NIFTY 2025-07-10 (4/18)
Error fetching NIFTY 2025-07-10: Client error '429 Too Many Requests' for url 'https://api.dhan.co/v2/optionchain'