Exception at calling ltp as {‘status’: ‘failure’, ‘remarks’: {‘error_code’: None, ‘error_type’: None, ‘error_message’: None}, ‘data’: ‘’}
Traceback (most recent call last):
File “MarketRobo.py”, line 37, in
ltp = ltp_for_all_script[name]
KeyError: ‘TCS’
Keep getting this error after few loop, it works for 5-10 While loops then keep getting this error.
Please suggest the fix
while True:
watchlist = Live_Trading.range(‘A2’).expand(‘down’).value #1. Read the Watchlist
current_time = datetime.datetime.now()
print("While Loop Started ", current_time, “\n\n”)
ltp_for_all_script = tsl.get_ltp_data(names = watchlist) #Get the LTP data from watchlist in one go
for name in watchlist:
#pdb.set_trace()
#ltp = tsl.get_ltp_data(names = name)[name] #2. Get the LTP one by one
ltp = ltp_for_all_script[name]
if name in ('NIFTY', 'BANKNIFTY', 'SENSEX'):
exchange_name = 'INDEX'
else:
exchange_name = 'NSE'
chart = tsl.get_historical_data(tradingsymbol = name, exchange = exchange_name, timeframe = "5") #3. Get the historical data 'INDEX' if name in ('NIFTY', 'SENSEX') else 'NSE'
