Local variable 'response' referenced before assignment

-----Logged into Dhan-----
reading existing file all_instrument 2025-04-10.csv
Got the instrument file
Scanning APOLLOHOSP
Scanning ASIANPAINT
Scanning AXISBANK
Scanning BAJAJ-AUTO
Scanning BAJFINANCE
buy BAJFINANCE
'Got exception in place_order as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: ‘DH-906’, ‘error_type’: ‘Order_Error’, ‘error_message’: ‘Market is Closed! Want to place an offline order?’}, ‘data’: {‘errorType’: ‘Order_Error’, ‘errorCode’: ‘DH-906’, ‘errorMessage’: ‘Market is Closed! Want to place an offline order?’}}
Error at get_executed_price as Check the order id, Error as None
Traceback (most recent call last):
File “C:\Users\ajitk\AppData\Local\Programs\Python\Python38\lib\site-packages\Dhan_Tradehull\Dhan_Tradehull.py”, line 1146, in get_executed_price
raise Exception(‘Check the order id, Error as None’)
Exception: Check the order id, Error as None

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “10. Managing Multiple Positions.py”, line 62, in
orderbook[name][‘entry_price’] = tsl.get_executed_price(orderid=entry_orderid)
File “C:\Users\ajitk\AppData\Local\Programs\Python\Python38\lib\site-packages\Dhan_Tradehull\Dhan_Tradehull.py”, line 1161, in get_executed_price
‘data’:response,
UnboundLocalError: local variable ‘response’ referenced before assignment

C:\Users\ajitk\Desktop\Dhan\Advance Algo Serise\Session 4>

Sir ye error aaraha hai please check karo na

Hi @AJIT_KUDALE ,

Orders won’t be placed after market closes because of which you are not getting the orderid. If you want to place order after market try placing AMO orders.

orderid = tsl.order_placement(tradingsymbol="ACC", exchange="NSE", quantity=1, price=0, trigger_price=0, order_type='MARKET', transaction_type='BUY', trade_type='MIS', after_market_order=True, amo_time='OPEN')

1 Like

I appreciate your response.
Your insights have significantly aided my trading journey, particularly regarding the perspective on trading that you provided in your Advanced Episode.
No amount of gratitude seems sufficient for the help you’ve given me. Thank you once more.

1 Like