FULL mode streaming DateTime stamp exception

ramatius
Hi,
When FULL mode streaming is enabled, the following error is seen in python,

File "/usr/local/lib/python2.7/dist-packages/simplejson/encoder.py", line 268, in default
raise TypeError(repr(o) + " is not JSON serializable")
exceptions.TypeError: datetime.datetime(2019, 12, 16, 14, 19, 53) is not JSON serializable

No such error in QUOTE mode.

How to resolve this issue? Pls advise.

Regards,
Ramakrishnan S
quantindia.in
  • rakeshr
    @ramatius
    exceptions.TypeError: datetime.datetime(2019, 12, 16, 14, 19, 53) is not JSON serializable
    Are you trying to dump WebSocket dictionary to the JSON object?
    If yes, you can follow either of the below approaches to dump to JSON object:
    1>Specifically convert DateTime field to string and then dump it.
    eg: data['timestamp'] = response['timestamp'].strftime("%Y-%m-%d %H:%M:%S")
    2>Convert everything it doesn't know to strings.
    eg:json.dumps(websocket_dic, indent=4, sort_keys=True, default=str)
    No such error in QUOTE mode.
    Yeah, as there isn't timestamp packet field(Last traded timestamp/Exchange timestamp) in Quote mode.
  • ramatius
    @rakeshr Yes, that fixed the problem.
    Thank you for the quick & accurate response.

    Regards,
    Ramakrishnan S
This discussion has been closed.