1006 connection closed abnormally

I am trying to run this example: martingale (https://alpaca.markets/learn/martingale-day-trading-python/)
and I get connection error after a couple of hours. I ran this via the paper account for a few days and I got the same error every day:

WARNING:root:code = 1006 (connection closed abnormally [internal]), no reason
Traceback (most recent call last):
File “view_trades.py”, line 143, in
trader.start_trading()

File “view_trades.py”, line 138, in start_trading
conn.run([f’alpacadatav1/T.{self.symbol}’, ‘trade_updates’])
File “…\anaconda3\envs\py36\lib\site-packages\alpaca_trade_api\stream2.py”, line 276, in run
loop.run_until_complete(self.consume())
File “…\anaconda3\envs\py36\lib\asyncio\base_events.py”, line 484, in run_until_complete
return future.result()
concurrent.futures._base.CancelledError

1 Like

I have the exact same issue. Did you solve it? Would love to know how to.

Thanks,
Randy

No I stopped using stream and I am just using REST now.

i tried REST but ran into too man api calls. I am going to try to figure it out.

I am having the same issues occasionally, but today it was occurring quite frequently. It is not clear if the Python Alpaca API stream subscription is able to recover and maintain the connection.
Any ideas if this is happening in the underlying code?

Interested in same answer.

Streaming data is so important for any auto trading strategy. Surprised that polygon/alpaca is not paying attending to resolving this asap as I see many people having the same issue of socket disconnections.

Atleast, please post any work arounds or reconnection examples.

1 Like