Skip to content

Commit

Permalink
Merge 02bdca3 into 4f08f38
Browse files Browse the repository at this point in the history
  • Loading branch information
liampauling authored Dec 3, 2020
2 parents 4f08f38 + 02bdca3 commit abbd4c0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
15 changes: 9 additions & 6 deletions flumine/baseflumine.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,15 @@ def _process_market_books(self, event: events.MarketBookEvent) -> None:

def _process_market_orders(self) -> None:
for market in self.markets:
if market.market_book:
bet_delay = market.market_book.bet_delay
else:
bet_delay = None
for order_package in market.blotter.process_orders(self.client, bet_delay):
self.handler_queue.put(order_package)
if market.blotter.pending_orders:
if market.market_book:
bet_delay = market.market_book.bet_delay
else:
bet_delay = None
for order_package in market.blotter.process_orders(
self.client, bet_delay
):
self.handler_queue.put(order_package)

def _process_order_package(self, order_package) -> None:
"""Validate trading controls and
Expand Down
15 changes: 14 additions & 1 deletion flumine/markets/blotter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Iterable, Tuple
from typing import Iterable

from ..order.ordertype import OrderTypes
from ..utils import chunks, calculate_unmatched_exposure, calculate_matched_exposure
Expand Down Expand Up @@ -73,6 +73,19 @@ def _create_packages(
orders.clear()
return packages

@property
def pending_orders(self) -> bool:
if self.pending_place:
return True
elif self.pending_cancel:
return True
elif self.pending_update:
return True
elif self.pending_replace:
return True
else:
return False

@property
def live_orders(self):
return iter(self._live_orders)
Expand Down
6 changes: 5 additions & 1 deletion tests/test_baseflumine.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,16 @@ def test__process_market_books(self):

def test__process_market_orders(self):
mock_market = mock.Mock()
mock_market.blotter.pending_orders = True
mock_market.blotter.process_orders.return_value = [1, 2, 3]
self.base_flumine.markets = [mock_market]
mock_market_two = mock.Mock()
mock_market_two.blotter.pending_orders = False
self.base_flumine.markets = [mock_market, mock_market_two]
self.base_flumine._process_market_orders()
mock_market.blotter.process_orders.assert_called_with(
self.mock_client, mock_market.market_book.bet_delay
)
mock_market_two.blotter.process_orders.assert_not_called()

def test__process_order_package(self):
mock_trading_control = mock.Mock()
Expand Down
5 changes: 5 additions & 0 deletions tests/test_blotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ def test___create_packages(self, mock_cls):
)
self.assertEqual(mock_orders, [])

def test_pending_orders(self):
self.assertFalse(self.blotter.pending_orders)
self.blotter.pending_update = [1]
self.assertTrue(self.blotter.pending_orders)

def test_live_orders(self):
self.assertEqual(list(self.blotter.live_orders), [])
mock_order = mock.Mock(complete=False)
Expand Down

0 comments on commit abbd4c0

Please sign in to comment.