I have no issues connecting to Polygon, sending subscription requests, and even receiving data streams. At least initially… It always connects and begins streaming reliably and everything looks fine, but just shy of 2 hours into streaming the data will suddenly stop and any additional messages sent to the socket will result in an error message saying the socket has already been disconnected. This seems to happen regardless of what time of day I start the stream.
I’m connecting to Polygon using the Polygon module in Python. I am also receiving data asynchronously to avoid any backlog in receiving the messages. Polygon’s docs don’t give me any clues nor do any of the messages I’m receiving from the server. I’ve been playing with this for a few weeks and I’m about to switch data providers over it since my goal is to stream data while I’m at work.
Any ideas? Am I missing something obvious here?
New here and I’m also seeing this. I’m suspecting it may be a problem with the way python is handling the websocket - going to try a quick go with a different language tomorrow.
In any case, I was able to write a loop to keep it restarting in python (just doing minute quotes), but there may still be the potential to lose a minute when it restarts. See https://gist.github.com/rainey/2e1e95d47e6a37edd6ab79fa3a595020 - there may be some errors there as I edited the gist from my working program
I contacted Polygon and got this response:
“This an issue that we are currently working to resolve. Apologies for the inconvenience.”
Not really enough information there to know if it’s a Python issue or not, but it sounds like we might be trying to compensate for an error on the server side.
Both Polygon and Alpaca are making efforts to keep it connected as much as possible, but by nature of TCP network over the internet, you should expect a connection is disconnected at some point, and it’s usually recommended to make sure you reconnect to the endpoint.
I saw similar behavior, it works for a while and then just stopped. Even with reconnection effort, it still fails:
def run_ws(conn, channels):
except Exception as e: