mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-11-29 08:33:07 +00:00
chore: update websocket implementation to new asyncio api
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from fastapi import WebSocket as FastAPIWebSocket
|
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
|
from freqtrade.rpc.api_server.ws.types import WebSocketType
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from typing import Any, TypeVar
|
from typing import Any, TypeVar
|
||||||
|
|
||||||
from fastapi import WebSocket as FastAPIWebSocket
|
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)
|
WebSocketType = TypeVar("WebSocketType", FastAPIWebSocket, WebSocket)
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ class ExternalMessageConsumer:
|
|||||||
ws_url = f"{scheme}://{host}:{port}/api/v1/message/ws?token={token}"
|
ws_url = f"{scheme}://{host}:{port}/api/v1/message/ws?token={token}"
|
||||||
|
|
||||||
# This will raise InvalidURI if the url is bad
|
# 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
|
ws_url, max_size=self.message_size_limit, ping_interval=None
|
||||||
) as ws:
|
) as ws:
|
||||||
async with create_channel(ws, channel_id=name, send_throttle=0.5) as channel:
|
async with create_channel(ws, channel_id=name, send_throttle=0.5) as channel:
|
||||||
|
|||||||
@@ -253,8 +253,7 @@ async def create_client(
|
|||||||
except (
|
except (
|
||||||
socket.gaierror,
|
socket.gaierror,
|
||||||
ConnectionRefusedError,
|
ConnectionRefusedError,
|
||||||
websockets.exceptions.InvalidStatusCode,
|
websockets.exceptions.InvalidHandshake,
|
||||||
websockets.exceptions.InvalidMessage,
|
|
||||||
) as e:
|
) as e:
|
||||||
logger.error(f"Connection Refused - {e} retrying in {sleep_time}s")
|
logger.error(f"Connection Refused - {e} retrying in {sleep_time}s")
|
||||||
await asyncio.sleep(sleep_time)
|
await asyncio.sleep(sleep_time)
|
||||||
|
|||||||
Reference in New Issue
Block a user