Skip to content

Commit

Permalink
Merge pull request #235 from liampauling/bugfix/232-dictionary-change…
Browse files Browse the repository at this point in the history
…d-size

orders list added during serialise to prevent RuntimeError
  • Loading branch information
liampauling committed Sep 30, 2019
2 parents d07f1c6 + 84cd285 commit c763c08
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion betfairlightweight/streaming/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,9 @@ def update_unmatched(self, unmatched_orders):
self.unmatched_orders[unmatched_order["id"]] = UnmatchedOrder(**unmatched_order)

def serialise_orders(self, market_id):
orders = list(self.unmatched_orders.values()) # order may be added (#232)
return [
order.serialise(market_id, self.selection_id, self.handicap) for order in self.unmatched_orders.values()
order.serialise(market_id, self.selection_id, self.handicap) for order in orders
]


Expand Down
20 changes: 20 additions & 0 deletions tests/unit/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,26 @@ def test_update_unmatched(self):
"c"
)

def test_serialise_orders(self):
mock_order = mock.Mock()
mock_order.id = 123
mock_order_two = mock.Mock()
mock_order_two.id = 456

unmatched_orders = {
mock_order.id: mock_order,
mock_order_two.id: mock_order_two,
}
self.order_book_runner.unmatched_orders = unmatched_orders

def mock_serialise(*args, **kwargs):
unmatched_orders[789] = "SYM"
return

mock_order_two.serialise = mock_serialise

assert len(self.order_book_runner.serialise_orders("1.1")), 2


class TestUnmatchedOrder(unittest.TestCase):

Expand Down

0 comments on commit c763c08

Please sign in to comment.