diff --git a/flumine/execution/betfairexecution.py b/flumine/execution/betfairexecution.py index 31c7ead5..bc04a0f0 100644 --- a/flumine/execution/betfairexecution.py +++ b/flumine/execution/betfairexecution.py @@ -29,6 +29,9 @@ def execute_place( if instruction_report.status == "SUCCESS": if instruction_report.order_status == "PENDING": pass # async request pending processing + elif instruction_report.order_status == "EXPIRED": + # avoids setting FOK orders to executable after process.py set them as complete + order.execution_complete() else: order.executable() # let process.py pick it up elif instruction_report.status == "FAILURE": diff --git a/tests/test_execution.py b/tests/test_execution.py index 473d89ec..d8134284 100644 --- a/tests/test_execution.py +++ b/tests/test_execution.py @@ -300,6 +300,37 @@ def test_execute_place_success_pending( mock_order.trade.__exit__.assert_called_with(None, None, None) mock_order_package.client.add_transaction.assert_called_with(1) + @mock.patch("flumine.execution.betfairexecution.BetfairExecution._order_logger") + @mock.patch("flumine.execution.betfairexecution.BetfairExecution.place") + @mock.patch("flumine.execution.betfairexecution.BetfairExecution._execution_helper") + def test_execute_place_success_expired( + self, mock__execution_helper, mock_place, mock__order_logger + ): + mock_session = mock.Mock() + mock_order = mock.Mock() + mock_order.trade.__enter__ = mock.Mock() + mock_order.trade.__exit__ = mock.Mock() + mock_order_package = mock.MagicMock() + mock_order_package.__len__.return_value = 1 + mock_order_package.__iter__ = mock.Mock(return_value=iter([mock_order])) + mock_order_package.info = {} + mock_report = mock.Mock() + mock_instruction_report = mock.Mock(status="SUCCESS", order_status="EXPIRED") + mock_report.place_instruction_reports = [mock_instruction_report] + mock__execution_helper.return_value = mock_report + self.execution.execute_place(mock_order_package, mock_session) + mock__execution_helper.assert_called_with( + mock_place, mock_order_package, mock_session + ) + mock__order_logger.assert_called_with( + mock_order, mock_instruction_report, OrderPackageType.PLACE + ) + mock_order.executable.assert_not_called() + mock_order.execution_complete.assert_called_with() + mock_order.trade.__enter__.assert_called_with() + mock_order.trade.__exit__.assert_called_with(None, None, None) + mock_order_package.client.add_transaction.assert_called_with(1) + @mock.patch("flumine.execution.betfairexecution.BetfairExecution._order_logger") @mock.patch("flumine.execution.betfairexecution.BetfairExecution.place") @mock.patch("flumine.execution.betfairexecution.BetfairExecution._execution_helper")