I am trying to get LTP data using following code but only getting data for the first stock “reliance”:
watchlist = [
‘RELIANCE’, ‘HDFCBANK’, ‘ICICIBANK’, ‘BHARTIARTL’,
‘INFY’, ‘SBIN’, ‘LICI’, ‘ITC’, ‘LT’ ]for stock_name in watchlist:
print(stock_name)ltp_data = tsl.get_ltp_data(names=stock_name)[stock_name]
Error :
RELIANCE
1328.8
HDFCBANK
Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: ‘’}
Traceback (most recent call last):
File “G:\python\3. Session3 - Codebase\3. Session3 - Codebase\Dhan codebase\algo1 - test.py”, line 57, in
ltp_data = tsl.get_ltp_data(names=stock_name)[stock_name]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: ‘HDFCBANK’
PLS HELP
