diff --git a/cryptofeed/connection.py b/cryptofeed/connection.py index b30570a07..13c79a08e 100644 --- a/cryptofeed/connection.py +++ b/cryptofeed/connection.py @@ -16,7 +16,7 @@ from aiohttp.client_reqrep import ClientResponse import requests -from websockets.asyncio.client import connect +from websockets.asyncio.client import connect, ClientConnection from websockets.protocol import State import aiohttp from aiohttp.typedefs import StrOrURL @@ -82,7 +82,7 @@ def __init__(self, conn_id: str, authentication=None, subscription=None): self.last_message = None self.authentication = authentication self.subscription = subscription - self.conn: Union[websockets.WebSocketClientProtocol, aiohttp.ClientSession] = None + self.conn: Union[ClientConnection, aiohttp.ClientSession] = None atexit.register(self.__del__) def __del__(self): diff --git a/cryptofeed/connection_handler.py b/cryptofeed/connection_handler.py index 9f1965c80..2753cc188 100644 --- a/cryptofeed/connection_handler.py +++ b/cryptofeed/connection_handler.py @@ -6,7 +6,6 @@ ''' import asyncio import logging -import random from socket import error as socket_error import time from typing import Awaitable @@ -51,7 +50,6 @@ async def _watcher(self): async def _create_connection(self): await asyncio.sleep(self.start_delay) retries = 0 - rate_limited = 1 delay = 1 while (retries <= self.retries or self.retries == -1) and self.running: try: @@ -60,7 +58,6 @@ async def _create_connection(self): await self.subscribe(connection) # connection was successful, reset retry count and delay retries = 0 - rate_limited = 0 delay = 1 if self.timeout != -1: loop = asyncio.get_running_loop() diff --git a/cryptofeed/exchanges/kucoin.py b/cryptofeed/exchanges/kucoin.py index 9b390be3d..174f14c33 100644 --- a/cryptofeed/exchanges/kucoin.py +++ b/cryptofeed/exchanges/kucoin.py @@ -285,7 +285,7 @@ async def subscribe(self, conn: AsyncConnection): await conn.write(json.dumps({ 'id': 1, 'type': 'subscribe', - 'topic': f"{chan}:{','.join(symbols[slice_index: slice_index+100])}", + 'topic': f"{chan}: {','.join(symbols[slice_index: slice_index + 100])}", 'privateChannel': False, 'response': True })) diff --git a/requirements.txt b/requirements.txt index 711f9f14d..b55426d81 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,5 +7,5 @@ order_book==0.6.1 pyyaml requests>=2.18.4 uvloop -websockets>=7.0 +websockets>=14.1 yapic.json>=1.6.3 \ No newline at end of file diff --git a/tools/websockets_test.py b/tools/websockets_test.py index ce7772783..3a3a4262c 100644 --- a/tools/websockets_test.py +++ b/tools/websockets_test.py @@ -32,6 +32,6 @@ async def main(): if not is_gzip: print(f"< {response}") else: - print(f"< {zlib.decompress(response, 16+zlib.MAX_WBITS)}") + print(f"< {zlib.decompress(response, 16 + zlib.MAX_WBITS)}") asyncio.get_event_loop().run_until_complete(main())