Issue with WebSocket V3 API – 403 Error After Network Failure
I am using the WebSocket V3 API with Python, and I am facing an issue when there is a sudden network failure on my side. When my network comes back, my script tries to reconnect, but I receive a 403 error, likely because the server still considers the previous WebSocket session as active and hasn’t closed it yet.
Error Log:
yaml
CopyEdit
2025-03-10 20:35:57,808 - INFO - Successfully authorized for WebSocket URL
2025-03-10 20:35:58,220 - ERROR - WebSocket rejected with HTTP 403: server rejected WebSocket connection: HTTP 403; will reauthorize
2025-03-10 20:35:58,221 - INFO - Retrying in 80 seconds...
The issue persists in both my standalone Python script and the official Python SDK (Market Data Streamer).
Observations:
- The WebSocket feed starts working again only after 10–15 minutes, suggesting that the server eventually times out and closes the stale connection.
- I suspect that my previous WebSocket session isn’t being properly closed, which prevents an immediate reconnection.
Questions:
- Is there a way to explicitly close the previous WebSocket connection before attempting to reconnect?
- Is there an alternative method to immediately regain the market data feed after a network failure, without waiting for the server to close the stale session?
Any insights or solutions would be greatly appreciated!