Source code for tradeexecutor.state.pickle_over_json

"""Serialise complex Python types to JSON using pickled hex.

- Serialises complex values (list, dicts, classes) as binary strings, pickled and encoded as hex.

- These values are not readable at the frontend. If you want to have frontend readable values,
  store human-readable copies
"""
import pickle


[docs]def encode_pickle_over_json(v: any): pickled = pickle.dumps(v) return pickled.hex()
[docs]def decode_pickle_over_json(v: str) -> any: if v is None: return None bin = bytearray.fromhex(v) unpickled = pickle.loads(bin) return unpickled