Cannot reconnect to Polygon Streamconn

Hi,

I’m seeing quite a few stream disconnection recently when I use Polygon Streamconn. It seems like it won’t reconnect automatically. I see the debug message below:

Debug data: Entity({   'ev': 'status',
    'message': 'Polygon Disconnected Unexpectedly (code = 1006 (connection '
               'closed abnormally [internal]), no reason)',
    'status': 'disconnected'})

I assume it should retry connect for 3 times, right? But I don’t see it’s happening.

I’m using version 0.49.0 BTW.

Any help would be appreciated!

Hi,
v0.50.1 is adding extended debug information for ws connectivity so it might help you understand what is going on.
just make sure you define your python logger so you will see the logs.

I’m seeing a lot disconnect recently. I’ve updated to 0.50.1 but don’t see other error message.

What I’m doing now is pull the latest alpaca package and build locally and add multiple logging here and there. What I found is that once it’s disconnected, it stucks at closing the websocket (at this line: https://github.com/alpacahq/alpaca-trade-api-python/blob/master/alpaca_trade_api/polygon/streamconn.py#L192)

I subscribed about 300 tickers, is that the reason ws cannot be closed?

Please take a look, thanks!

Hi, someone offered a solution for a similar issue, might help you too.
it’s when using polygon and when having an exception and closing the websocket.

could you install his branch locally and check if that solves your issue?

do it like this:
pip install git+https://github.com/drew-wallace/alpaca-trade-api-python@sockets-fix

Getting same 1006 no reason disconnect issues with polygon steam on minute data. Happens randomly. Is there an example python code to catch a disconnect and re-establish websocket connection to polygon stream?

Have alpaca live broker account and using alpaca-trade-api