consumer subscriptions, fix serializer bug

This commit is contained in:
Timothy Pogue
2022-08-29 15:48:29 -06:00
parent 7952e0df25
commit 47f7c384fb
5 changed files with 50 additions and 9 deletions

View File

@@ -4,22 +4,31 @@ import socket
import websockets
from freqtrade.enums import RPCMessageType
from freqtrade.rpc.api_server.ws.channel import WebSocketChannel
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
async def _client():
subscribe_topics = [RPCMessageType.WHITELIST]
try:
while True:
try:
url = "ws://localhost:8080/api/v1/message/ws?token=testtoken"
async with websockets.connect(url) as ws:
channel = WebSocketChannel(ws)
logger.info("Connection successful")
# Tell the producer we only want these topics
await channel.send(subscribe_topics)
while True:
try:
data = await asyncio.wait_for(
ws.recv(),
channel.recv(),
timeout=5
)
logger.info(f"Data received - {data}")
@@ -27,14 +36,14 @@ async def _client():
# We haven't received data yet. Check the connection and continue.
try:
# ping
ping = await ws.ping()
ping = await channel.ping()
await asyncio.wait_for(ping, timeout=2)
logger.debug(f"Connection to {url} still alive...")
continue
except Exception:
logger.info(
f"Ping error {url} - retrying in 5s")
asyncio.sleep(2)
await asyncio.sleep(2)
break
except (socket.gaierror, ConnectionRefusedError):