Skip to content

Commit

Permalink
Merge pull request #684 from lunswor/fill-or-kill-orders-stuck-execut…
Browse files Browse the repository at this point in the history
…able

Adds handling of FOK orders status getting stuck
  • Loading branch information
liampauling authored Oct 5, 2023
2 parents 02a397c + f52d21a commit 83e3375
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions flumine/execution/betfairexecution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
31 changes: 31 additions & 0 deletions tests/test_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 83e3375

Please sign in to comment.