Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR:root:error while consuming ws messages: cannot set a row with mismatched columns #26

Open
ghoshsanjoy78 opened this issue Aug 31, 2020 · 9 comments

Comments

@ghoshsanjoy78
Copy link

ghoshsanjoy78 commented Aug 31, 2020

I am trying to run the code. I goes as far as "Watching symbols"
But then it keeps hitting this error -
ERROR:root:error while consuming ws messages: cannot set a row with mismatched columns
What could be the issue and how do I fix it?

@jusmark123
Copy link

The new api version returns an additional column 'vwap' in the historic_agg_v2 call. Add the following just under the call

if 'vwap' in minute_history[symbol]:
             minute_history[symbol].drop('vwap', axis=1, inplace=True)

@Gabowatt
Copy link

Gabowatt commented Sep 9, 2020

@jusmark123 I just added this and it eliminated that issue but now it gets stuck on "watching symbols" forever. Have you faced a similar issue?

Change made:
for symbol in symbols:
minute_history[symbol] = api.polygon.historic_agg_v2(
timespan="minute", symbol=symbol, limit=1000, multiplier=1, _from=yesterday.strftime("%Y-%m-%d"), to=today.strftime("%Y-%m-%d")
).df
if 'vwap' in minute_history[symbol]:
minute_history[symbol].drop('vwap', axis=1, inplace=True)
c += 1
print('{}/{}'.format(c, len(symbols)))
print('Success.')
return minute_history

@jusmark123
Copy link

jusmark123 commented Sep 10, 2020 via email

@russelldouglas
Copy link

@Gabowatt @jusmark123 I am having the same problem in which, after fixing the mismatched columns, it just gets stuck on "watching symbols" forever. I have run it for multiple days now, and it never buys. Did either of your figure out why this is or fix it in some way?

@nickvertucci
Copy link

Any resolve to this? I have a running code that also stops at watching symbols

@GreengageLTD
Copy link

Have the same issue. Made the edit @jusmark123 offered but it still stalls. is it an issue with multiple feeds? Can a dummy column be inserted to match them up? What would that look like?

Getting current ticker data...
Success.
Tracking 158 symbols.
Getting historical data...
1/158
Success.
Watching 158 symbols.
ERROR:root:error while consuming ws messages: cannot set a row with mismatched columns
^CTraceback (most recent call last):
File "/home/primary/.local/lib/python3.6/site-packages/alpaca_trade_api/stream2.py", line 331, in run
loop.run_until_complete(self.consume())
File "/usr/lib/python3.6/asyncio/base_events.py", line 484, in run_until_complete
return future.result()
File "/home/primary/.local/lib/python3.6/site-packages/alpaca_trade_api/stream2.py", line 316, in consume
self.data_ws.consume(),
File "/home/primary/.local/lib/python3.6/site-packages/alpaca_trade_api/polygon/streamconn.py", line 108, in cons
ume
await self._consume_task
File "/home/primary/.local/lib/python3.6/site-packages/alpaca_trade_api/polygon/streamconn.py", line 114, in _con
sume_msg
await self._dispatch(data)
File "/home/primary/.local/lib/python3.6/site-packages/alpaca_trade_api/polygon/streamconn.py", line 221, in _dis
patch
await handler(self, channel, ent)
File "wm4_v2.txt", line 192, in handle_second_bar
minute_history[symbol].loc[ts] = new_data
File "/home/primary/.local/lib/python3.6/site-packages/pandas/core/indexing.py", line 670, in setitem
iloc._setitem_with_indexer(indexer, value)
File "/home/primary/.local/lib/python3.6/site-packages/pandas/core/indexing.py", line 1626, in _setitem_with_inde
xer
self._setitem_with_indexer_missing(indexer, value)
File "/home/primary/.local/lib/python3.6/site-packages/pandas/core/indexing.py", line 1856, in _setitem_with_inde
xer_missing
raise ValueError("cannot set a row with mismatched columns")
ValueError: cannot set a row with mismatched columns
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "wm4_v2.txt", line 401, in
run(get_tickers(), market_open, market_close)
File "wm4_v2.txt", line 372, in run

@jusmark123
Copy link

The error is telling you that the data being added to a dataFrame does have the same columns. You can place a print statement during iterations to find the issue. It shouldn't have anything to do with multiple streams. The trace states that it is happening in the run() function. You can print the DataFrame columns with df.columns.values.tolist() you can even set up a try/except statement that will catch the error so you can print the column. If you are using and IDE like spyder or pycharm then you can debug and step through the code to see your variables including dataFrame structure.

@GreengageLTD
Copy link

@jusmark123 Thank you. It looks a lot better today. I appreciate your help.

@domnicsavio
Copy link

I'm having the same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants