I am trying to output prices given by an API for each stock symbol, into an excel sheet. The code works to output the data into the command line, but once I tried putting it into a sheet, the code gives back this error,
File "C:\Users\sss\Documents\Python Programs\Bot\Td\td3.py", line 42, in get_ohlc
for symbol, lastPrice in kwargs.get('symbol'):
ValueError: too many values to unpack (expected 2)
I am not sure where to go from this point. The relevant code is below, and any help would be greatly appreciated !
data_sheet1 = pd.read_excel('C:\\Users\\sss\\Downloads\\companylist.xlsx', index_col=0)
data_impor = data_sheet1.head(2600)
workbook = xlsxwriter.Workbook('c:\\Users\\sss\\Downloads\\output.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write('A1', 'Stock')
worksheet.write('B1', 'Price')
row = 1
col = 0
def get_ohlc(**kwargs):
data = get_quotes(symbol=kwargs.get('symbol'))
for symbol in kwargs.get('symbol'):
print(symbol)
print(data[symbol]['lastPrice'])
for symbol, lastPrice in kwargs.get('symbol'):
worksheet.write(row, col, symbol)
worksheet.write(row, col + 1, lastPrice)
row += 1
workbook.close()
for row in data_impor.index:
get_ohlc(symbol=[row])
symbolto be stored inkwargs['symbol']but in the secondforloop withinget_ohlcyou expect 'symbol` andlastPriceto be stored inkwargs['symbol']. Which one is it? Did you mean to reference a different key of thekwargsdictionary?