You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've run into an issue using the order stream which results in exceptions like the following (order_queue is a Queue which is the output_queue for a StreamListener):
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/aaron/workspace/xxx/xxx/order_feed/order_feed.py", line 35, in run
order_book = self.order_queue.get()
File "/usr/local/lib/python2.7/dist-packages/betfairlightweight/resources/baseresource.py", line 63, in json
return json.dumps(self._data)
File "/usr/lib/python2.7/json/__init__.py", line 244, in dumps
return _default_encoder.encode(obj)
File "/usr/lib/python2.7/json/encoder.py", line 207, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python2.7/json/encoder.py", line 270, in iterencode
return _iterencode(o, 0)
File "/usr/lib/python2.7/json/encoder.py", line 184, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: datetime.datetime(2017, 2, 16, 11, 18, 59) is not JSON serializable
On further testing, this appeared to happen when the CurrentOrders returned from the OrderBookCache contained an UnmatchedOrder which had a matched_date field that was not None (it was a datetime.datetime object).
As you can see from the placedDate field a few lines down, that datetime.datetime object is converted to its string representation when being serialised:
I've run into an issue using the order stream which results in exceptions like the following (order_queue is a Queue which is the output_queue for a StreamListener):
On further testing, this appeared to happen when the CurrentOrders returned from the OrderBookCache contained an UnmatchedOrder which had a matched_date field that was not None (it was a datetime.datetime object).
As you can see from the placedDate field a few lines down, that datetime.datetime object is converted to its string representation when being serialised:
https://github.com/liampauling/betfairlightweight/blob/master/betfairlightweight/resources/streamingresources.py#L425
The terminology as described in the documentation is quite confusing:
http://docs.developer.betfair.com/docs/display/1smk3cen4v3lu3yomq5qye0ni/Exchange+Stream+API#ExchangeStreamAPI-OCM/OrderChangeMessag
It seems like an UnmatchedOrder can contain a matched_date in the cases of partial matches.
I've created a pull request which contains the change I made locally to get it to work - you may have a nicer way of dealing with it.
#39
The text was updated successfully, but these errors were encountered: