Skip to content

Commit

Permalink
#327 correctly return orderStatus
Browse files Browse the repository at this point in the history
market/limit on close now execution complete on success
limit status now correct on place
  • Loading branch information
liampauling committed Dec 5, 2020
1 parent 4f08f38 commit bcef22c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
13 changes: 11 additions & 2 deletions flumine/backtest/simulated.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,20 @@ def place(
return self._create_place_response(bet_id)

def _create_place_response(
self, bet_id: int, status: str = "SUCCESS", error_code: str = None
self,
bet_id: int,
status: str = "SUCCESS",
order_status: str = None,
error_code: str = None,
) -> SimulatedPlaceResponse:
if order_status is None:
if self.size_remaining == 0:
order_status = "EXECUTION_COMPLETE"
else:
order_status = "EXECUTABLE"
return SimulatedPlaceResponse(
status=status,
order_status="EXECUTABLE", # todo?
order_status=order_status,
bet_id=str(bet_id),
average_price_matched=self.average_price_matched,
size_matched=self.size_matched,
Expand Down
4 changes: 2 additions & 2 deletions flumine/backtest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def __iter__(self):
class SimulatedPlaceResponse:
def __init__(
self,
status: str,
order_status: str = None,
status: str, # SUCCESS, FAILURE or TIMEOUT
order_status: str = None, # PENDING, EXECUTION_COMPLETE, EXECUTABLE or EXPIRED
bet_id: str = None,
average_price_matched: float = None,
size_matched: float = None,
Expand Down
18 changes: 16 additions & 2 deletions tests/test_simulated.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,21 +192,35 @@ def test_place_limit_removed_runner(self, mock__get_runner):
self.assertEqual(resp.error_code, "RUNNER_REMOVED")
self.assertEqual(self.simulated.matched, [])

def test_place_else(self):
@mock.patch("flumine.backtest.simulated.Simulated._create_place_response")
def test_place_else(self, mock__create_place_response):
mock_client = mock.Mock(best_price_execution=True)
self.simulated.order.order_type.ORDER_TYPE = OrderTypes.MARKET_ON_CLOSE
mock_market_book = mock.Mock()
self.simulated.place(mock_client, mock_market_book, {}, 1)
self.assertEqual(self.simulated.matched, [])
mock__create_place_response.assert_called_with(1)

def test__create_place_response(self):
resp = self.simulated._create_place_response(
1234, "FAILURE", "dubs of the mad skint and british"
1234, "FAILURE", error_code="dubs of the mad skint and british"
)
self.assertEqual(resp.bet_id, "1234")
self.assertEqual(resp.status, "FAILURE")
self.assertEqual(resp.order_status, "EXECUTABLE")
self.assertEqual(resp.error_code, "dubs of the mad skint and british")

@mock.patch(
"flumine.backtest.simulated.Simulated.size_remaining",
new_callable=mock.PropertyMock,
return_value=0,
)
def test__create_place_response_complete(self):
resp = self.simulated._create_place_response(1234)
self.assertEqual(resp.bet_id, "1234")
self.assertEqual(resp.status, "SUCCESS")
self.assertEqual(resp.order_status, "EXECUTION_COMPLETE")

def test_cancel(self):
self.simulated.order.update_data = {}
resp = self.simulated.cancel()
Expand Down

0 comments on commit bcef22c

Please sign in to comment.