Code review fixes

This commit is contained in:
Ian Renton
2026-09-18 07:56:08 +01:00
parent 0fa8cd763d
commit a03e1336c8
18 changed files with 113 additions and 66 deletions
+17 -3
View File
@@ -50,8 +50,13 @@ class WebsocketSpotProvider(SpotProvider):
self.status = "Connecting"
self._ws = create_connection(self._url, header=HTTP_HEADERS)
self.status = "Connected"
data = self._ws.recv()
if data:
# Keep reading from this same connection until it drops or we're asked to stop, rather than
# reconnecting for every message.
while not self._stopped:
data = self._ws.recv()
if not data:
break
try:
new_spot = self._ws_message_to_spot(data)
if new_spot:
@@ -69,7 +74,16 @@ class WebsocketSpotProvider(SpotProvider):
logger.exception(f"Exception in Websocket Spot Provider ({self.name})")
else:
self.status = "Disconnected"
sleep(5) # Wait before trying to reconnect
finally:
if self._ws:
try:
self._ws.close()
except Exception:
# No problem, we were getting rid of this object anyway.
pass
self._ws = None
if not self._stopped:
sleep(5) # Wait before trying to reconnect
def _ws_message_to_spot(self, b):
"""Convert a WS message received from the API into a spot. The exact message data (in bytes) is provided here so the