Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnmatchedOrder.matched_date is not serialisable #40

Closed
agberk opened this issue Feb 16, 2017 · 1 comment
Closed

UnmatchedOrder.matched_date is not serialisable #40

agberk opened this issue Feb 16, 2017 · 1 comment

Comments

@agberk
Copy link
Contributor

agberk commented Feb 16, 2017

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:

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

@liampauling
Copy link
Member

Weird that I have never encountered this, will merge asap.

seaders pushed a commit to seaders/betfairlightweight that referenced this issue May 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants