Stream Broken with Alpaca-Trade-API version 0.48 / api version 0.46 working

If I use alpaca-trade-api version 0.46, the example demo works:

pip3 install alpaca_trade_api==0.46

python --all (under alpaca-trade-api-python/examples directory from github repository)

Example Output (seems OK):

2020-06-23 04:28:43.841834 debug: Entity({‘ev’: ‘status’, ‘message’: ‘Connecting to Polygon’, ‘status’: ‘connecting’})
2020-06-23 04:28:44.060167 debug: Entity({‘ev’: ‘status’, ‘message’: ‘Connected Successfully’, ‘status’: ‘connected’})
2020-06-23 04:28:44.200134 debug: Entity({‘ev’: ‘status’, ‘message’: ‘authenticated’, ‘status’: ‘auth_success’})
2020-06-23 04:28:44.250377 debug: Entity({‘ev’: ‘status’, ‘message’: ‘subscribed to: Q.’, ‘status’: ‘success’})
2020-06-23 04:28:44.251205 debug: Entity({‘ev’: ‘status’, ‘message’: 'subscribed to: T.
’, ‘status’: ‘success’})
2020-06-23 04:28:44.253505 debug: Entity({‘ev’: ‘status’, ‘message’: ‘subscribed to: AM.’, ‘status’: ‘success’})
2020-06-23 04:28:44.258159 debug: Entity({‘ev’: ‘status’, ‘message’: 'subscribed to: A.
’, ‘status’: ‘success’})
A 2020-06-23 AAL 0.00% 14.41 14.41 158
A 2020-06-23 BA 0.00% 191.20 191.25 300
A 2020-06-23 GLD 0.00% 165.19 165.19 800
A 2020-06-23 KTOV 0.00% 0.94 0.94 100
A 2020-06-23 IDEX 0.00% 3.65 3.65 260

Here is broken output using api version 0.48:

( pip3 install alpaca_trade_api==0.48 )

unknown channel A.* (you may need to specify the right data_stream)
ERROR:asyncio:Task was destroyed but it is pending!
task: <Task pending name=‘Task-1’ coro=<reloadWatch..watch_command() running at> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f16f48aa460>()]>>

Hi. Did you figure it out?

Unfortunately, I just updated to to the latest alpaca_trade_api version 0.50.1, installed the common and test requirements, installed the alpaca_trade_api, and tested the example with similar results:

python3 --all

ERROR:root:error while consuming ws messages: unknown channel A.* (you may need to specify the right data_stream)

alpaca_trade_api version 0.46 is still working fine for all streams:

pip3 install alpaca_trade_api==0.46

python3 --all

2020-09-26 06:25:40.184001 debug: Entity({‘ev’: ‘status’, ‘message’: ‘Connecting to Polygon’, ‘status’: ‘connecting’})
2020-09-26 06:25:40.438986 debug: Entity({‘ev’: ‘status’, ‘message’: ‘Connected Successfully’, ‘status’: ‘connected’})
2020-09-26 06:25:40.699630 debug: Entity({‘ev’: ‘status’, ‘message’: ‘authenticated’, ‘status’: ‘auth_success’})
2020-09-26 06:25:40.747909 debug: Entity({‘ev’: ‘status’, ‘message’: ‘subscribed to: Q.’, ‘status’: ‘success’})
2020-09-26 06:25:40.752791 debug: Entity({‘ev’: ‘status’, ‘message’: 'subscribed to: T.
’, ‘status’: ‘success’})
2020-09-26 06:25:40.758128 debug: Entity({‘ev’: ‘status’, ‘message’: ‘subscribed to: AM.’, ‘status’: ‘success’})
2020-09-26 06:25:40.762990 debug: Entity({‘ev’: ‘status’, ‘message’: 'subscribed to: A.
’, ‘status’: ‘success’})

Very strange - this test seems straightforward, perhaps I am doing something fundamentally incorrect? I can investigate the code and find a solution myself, but was hoping to save some time and effort by querying this forum.

Is anyone else having this issue? Is this forum active - anybody out there after 3 months of posing the question?

Thanks very much for your assistance. Best Regards.

Hi Guys, this is an updated example code using both the Alpaca data stream and the Polygon data stream (you could choose).
it uses the latest sdk version and it shows different things you could do with the stream.

try it out, and I am available for any question you may have regarding its usage:

Thanks very much for your response.

I compared the stream output this morning with the example previously provided by Hitoshi Harada using an earlier alpaca trade api (version 0.46). The outputs are significantly different (from Polygon), using the default connect option “[‘trade_updates’, ‘AM.’, 'A.’, ‘Q.’, 'T.’])” in the new example. Perhaps I am missing something fundamental, but why would the example contain much more output using the same stream connection?

I sincerely appreciate your assistance. Thanks again.

that example filters out data from the screen (so it will not be too verbose).
this code is a usage example, so it has no trading logic.

you could see in the code lines like this: if sec_agg_count % 1000 == 0 which prints 1 out of 1000 messages.

if you want to see all messages, change these lines


Any idea why the Polygon stream keeps disconnecting with “asyncio.exceptions.CancelledError” from line 293 in alpaca-trade-api code (v 0.50.1) ? It looks like the code is attempting to reconnect, but fails.

The asyncio web sockets disconnects every couple of minutes, during normal market activity. The code must be restarted manually. Does anyone have a better solution to avoid the api error?

When testing the Alpaca stream option, the data appears to be quite different from the polygon streams - perhaps a delay? Has anyone compared the two streams for consistency, timing, and quality?

Thanks very much for your assistance and attention to these matters.

Best Regards

Hi, I do not experience any issues with the polygon ws. is it consistent? do you still experience it.
do note that using the polygon ws is only possible for funded account.
I recommend installing a fresh env with the latest packages, and using the sample code I pointed out last time.

Thanks very much for responding.

I have a funded account and have been using the polygon streaming service for over a year, without any issues. After alpaca-trade-api version 0.46, the polygon streaming service and the example streaming code became unstable.

Do you have any issues running the “” example in the alpaca-trade-api-polygon/examples directory with a recent alpaca-trade-api ? Comparing it to your code, it seems to be a simple fix - just haven’t had time to investigate further.

Thanks for providing the sample websocket code. It works fine, but exits every several minutes. I came up with a stable websocket solution this weekend, using some Polygon clent and websocket examples from their github repositories and a restart callback procedure.

I found your github repository yesterday for using a proxy network service to run multiple streaming clients - very nice work ! I started working with the docker image to connect to the Polygon services. Haven’t tried multiple clients yet.

Apologies, I am a scientist and engineer by background and just learning about streaming services - very interesting, however.


Joseph Oravetz

The example needs an update and I will do that soon. for now you should use the which does the same functionality but in a simpler more straight forward way.

the works perfectly with the most updated sdk version (0.51.0) you should update to that version

happy to help :slight_smile:

1 Like

For other users wondering, I wanted to confirm that works great for alpaca.

Just think of as deprecated for now.