hybrid json ws serializer
This commit is contained in:
parent
eb4cd6ba82
commit
5b0b802f31
@ -3,7 +3,8 @@ from threading import RLock
|
|||||||
from typing import List, Type
|
from typing import List, Type
|
||||||
|
|
||||||
from freqtrade.rpc.api_server.ws.proxy import WebSocketProxy
|
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
|
from freqtrade.rpc.api_server.ws.types import WebSocketType
|
||||||
|
|
||||||
|
|
||||||
@ -18,7 +19,7 @@ class WebSocketChannel:
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
websocket: WebSocketType,
|
websocket: WebSocketType,
|
||||||
serializer_cls: Type[WebSocketSerializer] = RapidJSONWebSocketSerializer
|
serializer_cls: Type[WebSocketSerializer] = HybridJSONWebSocketSerializer
|
||||||
):
|
):
|
||||||
# The WebSocket object
|
# The WebSocket object
|
||||||
self._websocket = WebSocketProxy(websocket)
|
self._websocket = WebSocketProxy(websocket)
|
||||||
|
@ -3,6 +3,7 @@ import logging
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
import msgpack
|
import msgpack
|
||||||
|
import orjson
|
||||||
import rapidjson
|
import rapidjson
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
|
|
||||||
@ -55,6 +56,14 @@ class RapidJSONWebSocketSerializer(WebSocketSerializer):
|
|||||||
return rapidjson.loads(data, object_hook=_json_object_hook)
|
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):
|
class MsgPackWebSocketSerializer(WebSocketSerializer):
|
||||||
def _serialize(self, data):
|
def _serialize(self, data):
|
||||||
return msgpack.packb(data, use_bin_type=True)
|
return msgpack.packb(data, use_bin_type=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user