Related Dhan Algo ATM_Strike_Selection and get_ltp_data function error

Hello Team,
I’m trying to build a Algo with Dhan API. I have seen your videos, and explanation is very good.
But my Query is When I’m fetching ATM / OTM like (tsl.ATM_Strike_Selection) and tsl.get_ltp_data.
For this data is not fetching properly.
I have shared sample code and error or output here.

Please check and give me solution for this if any.

Strike Slection for options

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

print(atm_call_name,“\t” ,atm_put_name,“\t” , atm_strike)

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_call_name,“\t” ,otm_put_name,“\t” , otm_call_strike,“\t” , otm_put_strike)

Output is:

NIFTY 18 AUG 24350 CALL NIFTY 18 AUG 24350 PUT 24350
Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: ‘’}
Getting Error at OTM strike Selection as ‘NIFTY’

More details:
I have installed .exe that you have shared but not using Cursor AI. Using VS code as editor.

Your solution will help me a lot.
Thanks.

Hi @Keshav_Aher ,

Refer this code -

from Dhan_Tradehull import Tradehull
client_code = ""
tsl = Tradehull(client_code, mode="pin_totp", pin="", totp_secret="")

atm_call_name, atm_put_name, atm_strike = tsl.ATM_Strike_Selection(Underlying='NIFTY', Expiry=0)
print(f"ATM Call Name: {atm_call_name}, ATM Put Name: {atm_put_name}, ATM Strike: {atm_strike}")

Output

image

Thank you sir.