What is the rate limit of DHAN API?

Hi,
rate limit whatever that is mentioned here is misleading. I did some test and rate limit for data apis are 1 req/sec. Why ? Other brokers provides reasonable API limits.

import datetime

while True:

print(f"curren time: {datetime.datetime.now().strftime(‘%H:%M:%S’)}")

print(tsl.get_ltp_data(names=“HINDALCO”))

Output:
curren time: 07:12:10
{‘HINDALCO’: 954.95}
curren time: 07:12:10
Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: ‘’}
{}
curren time: 07:12:11
{‘HINDALCO’: 954.95}
curren time: 07:12:11
Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: ‘’}
{}
curren time: 07:12:12
{‘HINDALCO’: 954.95}
curren time: 07:12:12
Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: ‘’}
{}

And you guys really need to fix the error handling.

@Dhan can you look here ASAP.

You can fetch upto 1000 instruments in single API request with rate limit of 1 request per second.

Reference - Market Quote - DhanHQ Ver 2.0 / API Document

What is the rate limit of the above API ?
I am referencing from here - dhan website
But when I calculated it’s not giving whatever is claimed in website

  1. This is not an official package by Dhan.
  2. Official Python package respect the above mentioned rate limits - Market Quote - DhanHQ-py Document
  3. Verify source code here - DhanHQ-py/src/dhanhq/_market_feed.py at ff2ea961ba4ce834dd982d4204e2d41357b80a88 · dhan-oss/DhanHQ-py · GitHub

As mentioned here the rate limits - What is the rate limit of DHAN API? - #3 by DSingh . You logs says 2 requests per second. And that is why only first request of every second is working.

import time

import datetime

count = 0

fail = 0

start = time.time()

while time.time() - start < 10: # run 10 seconds

try:

res = tsl.get_ltp_data(names=“HINDALCO”)

if not res:

fail += 1

except:

fail += 1

count += 1

end = time.time()

duration = end - start

rps = count / duration

print(“Total Requests:”, count)

print(“Failures:”, fail)

print(“Duration:”, duration)

print(“Actual RPS:”, rps)

OUTPUT:

Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: ‘’}
Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: ‘’}
Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: ‘’}
Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: ‘’}
Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: ‘’}
Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: ‘’}
Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: ‘’}
Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: ‘’}
Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: ‘’}
Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: ‘’}
Total Requests: 20
Failures: 10
Duration: 10.158710956573486
Actual RPS: 1.9687537213624948

In the official docs it’s mentioned 5RPS.

Rate limits are different for each API and their endpoints. For Market Quote API it is 1 request per second as already mentioned. What is the rate limit of DHAN API? - #3 by DSingh

Thank you for clarification

If anyone wants to avoid that ratelimitting just create a wrapper API on top of ltp method. Make this as a global API and call this from your multiple strategy.