From 8f261d8edff162e26ad42876b2a4ce88beb08d45 Mon Sep 17 00:00:00 2001 From: Timothy Pogue Date: Mon, 5 Sep 2022 13:47:17 -0600 Subject: [PATCH] change from bytes to text in websocket, remove old logs --- freqtrade/rpc/api_server/api_ws.py | 2 -- freqtrade/rpc/api_server/ws/channel.py | 3 --- freqtrade/rpc/api_server/ws/proxy.py | 15 +++++++++------ freqtrade/rpc/api_server/ws/serializer.py | 2 ++ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/freqtrade/rpc/api_server/api_ws.py b/freqtrade/rpc/api_server/api_ws.py index d11d1acfe..aaa526401 100644 --- a/freqtrade/rpc/api_server/api_ws.py +++ b/freqtrade/rpc/api_server/api_ws.py @@ -67,8 +67,6 @@ async def _process_consumer_request( # They requested the full historical analyzed dataframes analyzed_df = rpc._ws_request_analyzed_df(limit) - logger.debug(f"ANALYZED_DF RESULT: {analyzed_df}") - # For every dataframe, send as a separate message for _, message in analyzed_df.items(): await channel.send({"type": RPCMessageType.ANALYZED_DF, "data": message}) diff --git a/freqtrade/rpc/api_server/ws/channel.py b/freqtrade/rpc/api_server/ws/channel.py index 1f0cd9c7a..952b3b9f5 100644 --- a/freqtrade/rpc/api_server/ws/channel.py +++ b/freqtrade/rpc/api_server/ws/channel.py @@ -50,7 +50,6 @@ class WebSocketChannel: """ Send data on the wrapped websocket """ - # logger.info(f"Serialized Send - {self._wrapped_ws._serialize(data)}") await self._wrapped_ws.send(data) async def recv(self): @@ -168,8 +167,6 @@ class ChannelManager: :param direct_channel: The WebSocketChannel object to send data through :param data: The data to send """ - # We iterate over the channels to get reference to the websocket object - # so we can disconnect incase of failure await channel.send(data) def has_channels(self): diff --git a/freqtrade/rpc/api_server/ws/proxy.py b/freqtrade/rpc/api_server/ws/proxy.py index 73d1481b9..ea977a228 100644 --- a/freqtrade/rpc/api_server/ws/proxy.py +++ b/freqtrade/rpc/api_server/ws/proxy.py @@ -27,11 +27,14 @@ class WebSocketProxy: """ Send data on the wrapped websocket """ - if isinstance(data, str): - data = data.encode() - if hasattr(self._websocket, "send_bytes"): - await self._websocket.send_bytes(data) + if not isinstance(data, str): + # We use HybridJSONWebSocketSerializer, which when serialized returns + # bytes because of ORJSON, so we explicitly decode into a string + data = str(data, "utf-8") + + if hasattr(self._websocket, "send_text"): + await self._websocket.send_text(data) else: await self._websocket.send(data) @@ -39,8 +42,8 @@ class WebSocketProxy: """ Receive data on the wrapped websocket """ - if hasattr(self._websocket, "receive_bytes"): - return await self._websocket.receive_bytes() + if hasattr(self._websocket, "receive_text"): + return await self._websocket.receive_text() else: return await self._websocket.recv() diff --git a/freqtrade/rpc/api_server/ws/serializer.py b/freqtrade/rpc/api_server/ws/serializer.py index 109708cc9..8ff617f45 100644 --- a/freqtrade/rpc/api_server/ws/serializer.py +++ b/freqtrade/rpc/api_server/ws/serializer.py @@ -58,9 +58,11 @@ class RapidJSONWebSocketSerializer(WebSocketSerializer): class HybridJSONWebSocketSerializer(WebSocketSerializer): def _serialize(self, data): + # ORJSON returns bytes return orjson.dumps(data, default=_json_default) def _deserialize(self, data): + # RapidJSON expects strings return rapidjson.loads(data, object_hook=_json_object_hook)