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'
