Help with error: alpacahq / Momentum-Trading-Example > algo.py

When I execute algo.py:

Fatal Python error: Cannot recover from stack overflow.
Current thread 0x00007f936ea52740 (most recent call first):
File “/usr/lib/python3.7/asyncio/base_events.py”, line 480 in _check_closed
File “/usr/lib/python3.7/asyncio/base_events.py”, line 560 in run_until_complete
File “/usr/local/lib/python3.7/dist-packages/alpaca_trade_api/stream2.py”, line 275 in run
File “algo.py”, line 383 in run_ws
File “algo.py”, line 387 in run_ws
File “algo.py”, line 387 in run_ws
File “algo.py”, line 387 in run_ws
File “algo.py”, line 387 in run_ws
File “algo.py”, line 387 in run_ws
File “algo.py”, line 387 in run_ws
File “algo.py”, line 387 in run_ws
File “algo.py”, line 387 in run_ws
File “algo.py”, line 387 in run_ws
File “algo.py”, line 387 in run_ws
File “algo.py”, line 387 in run_ws

Here is the full error message:

Getting current ticker data…
Success.
Tracking 226 symbols.
Getting historical data…
1/226
.
.
.
226/226
Success.
Watching 226 symbols.
unknown channel A.BBAR (you may need to specify the right data_stream)
algo.py:386: RuntimeWarning: coroutine ‘StreamConn.close’ was never awaited
conn.close()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Event loop is closed
.
.
.
Event loop is closed
Fatal Python error: Cannot recover from stack overflow.
Current thread 0x00007f681b498740 (most recent call first):
File “/usr/lib/python3.7/asyncio/base_events.py”, line 480 in _check_closed
File “/usr/lib/python3.7/asyncio/base_events.py”, line 560 in run_until_complete
File “/usr/local/lib/python3.7/dist-packages/alpaca_trade_api/stream2.py”, line 275 in run
File “algo.py”, line 383 in run_ws
.
.
.
File “algo.py”, line 387 in run_ws

Aborted

many problems with your code. First it shows that there is a problem with run_ws, this means that first I would debug that method specifically with not 226 stocks, but with maybe just 1 or 2 stocks, so you can get an idea of what the code is doing as a whole. Next we can see that close() was never awaited. So what I would do is, close the connection the catch block if Alapca drops your stream connection at any time. It is telling you that it cannot consume A. channel since that is second level market data which only polygon provides…

This also seems to be using (“A”) regexing in the ws columns, Alpaca only supports AM. regex. What does this mean, this means that Alpaca will only serve up to minute bars and not second bars which polygon does provide. Either change each channel to handle AM. instead of A. or just use the polygon endpoint since Alpaca is middlemanning polygon…