Skip to content

Commit

Permalink
chore: update websocket implementation to new asyncio api
Browse files Browse the repository at this point in the history
  • Loading branch information
xmatthias committed Nov 11, 2024
1 parent c9fb3df commit 60ec973
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion freqtrade/rpc/api_server/ws/proxy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any

from fastapi import WebSocket as FastAPIWebSocket
from websockets.legacy.client import WebSocketClientProtocol as WebSocket
from websockets.asyncio.client import ClientConnection as WebSocket

from freqtrade.rpc.api_server.ws.types import WebSocketType

Expand Down
2 changes: 1 addition & 1 deletion freqtrade/rpc/api_server/ws/types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any, TypeVar

from fastapi import WebSocket as FastAPIWebSocket
from websockets.legacy.client import WebSocketClientProtocol as WebSocket
from websockets.asyncio.client import ClientConnection as WebSocket


WebSocketType = TypeVar("WebSocketType", FastAPIWebSocket, WebSocket)
Expand Down
2 changes: 1 addition & 1 deletion freqtrade/rpc/external_message_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ async def _create_connection(self, producer: Producer, lock: asyncio.Lock):
ws_url = f"{scheme}://{host}:{port}/api/v1/message/ws?token={token}"

# This will raise InvalidURI if the url is bad
async with websockets.legacy.client.connect(
async with websockets.connect(
ws_url, max_size=self.message_size_limit, ping_interval=None
) as ws:
async with create_channel(ws, channel_id=name, send_throttle=0.5) as channel:
Expand Down
3 changes: 1 addition & 2 deletions scripts/ws_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ async def create_client(
except (
socket.gaierror,
ConnectionRefusedError,
websockets.exceptions.InvalidStatusCode,
websockets.exceptions.InvalidMessage,
websockets.exceptions.InvalidHandshake,
) as e:
logger.error(f"Connection Refused - {e} retrying in {sleep_time}s")
await asyncio.sleep(sleep_time)
Expand Down

0 comments on commit 60ec973

Please sign in to comment.