hybrid json ws serializer

This commit is contained in:
Timothy Pogue 2022-09-02 00:05:36 -06:00
parent eb4cd6ba82
commit 5b0b802f31
2 changed files with 12 additions and 2 deletions

View File

@ -3,7 +3,8 @@ from threading import RLock
from typing import List, Type
from freqtrade.rpc.api_server.ws.proxy import WebSocketProxy
from freqtrade.rpc.api_server.ws.serializer import RapidJSONWebSocketSerializer, WebSocketSerializer
from freqtrade.rpc.api_server.ws.serializer import (HybridJSONWebSocketSerializer,
WebSocketSerializer)
from freqtrade.rpc.api_server.ws.types import WebSocketType
@ -18,7 +19,7 @@ class WebSocketChannel:
def __init__(
self,
websocket: WebSocketType,
serializer_cls: Type[WebSocketSerializer] = RapidJSONWebSocketSerializer
serializer_cls: Type[WebSocketSerializer] = HybridJSONWebSocketSerializer
):
# The WebSocket object
self._websocket = WebSocketProxy(websocket)

View File

@ -3,6 +3,7 @@ import logging
from abc import ABC, abstractmethod
import msgpack
import orjson
import rapidjson
from pandas import DataFrame
@ -55,6 +56,14 @@ class RapidJSONWebSocketSerializer(WebSocketSerializer):
return rapidjson.loads(data, object_hook=_json_object_hook)
class HybridJSONWebSocketSerializer(WebSocketSerializer):
def _serialize(self, data):
return orjson.dumps(data, default=_json_default)
def _deserialize(self, data):
return rapidjson.loads(data, object_hook=_json_object_hook)
class MsgPackWebSocketSerializer(WebSocketSerializer):
def _serialize(self, data):
return msgpack.packb(data, use_bin_type=True)