Skip to content

Commit

Permalink
missing paper trade logic added on market closure
Browse files Browse the repository at this point in the history
  • Loading branch information
liampauling committed Aug 10, 2020
1 parent f7a0f07 commit 5fd4940
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
7 changes: 7 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
Release History
---------------

1.10.6 (2020-08-10)
+++++++++++++++++++

**Bug Fixes**

- Prevent closed markets being removed when paper trading

1.10.5 (2020-08-04)
+++++++++++++++++++

Expand Down
2 changes: 1 addition & 1 deletion flumine/__version__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__title__ = "flumine"
__description__ = "Betfair trading framework"
__url__ = "https://github.com/liampauling/flumine"
__version__ = "1.10.5"
__version__ = "1.10.6"
__author__ = "Liam Pauling"
__license__ = "MIT"
2 changes: 1 addition & 1 deletion flumine/baseflumine.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def _process_close_market(self, event: events.CloseMarketEvent) -> None:

# check for markets that have been closed for x seconds and remove
if (
self.BACKTEST is False
self.BACKTEST is False and self.client.paper_trade is False
): # due to monkey patching this will clear backtested markets
closed_markets = [
m
Expand Down
25 changes: 25 additions & 0 deletions tests/test_baseflumine.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,31 @@ def test__process_close_market_closed(self, mock_log_control, mock_info):

self.assertEqual(len(self.base_flumine.markets._markets), 3)

@mock.patch("flumine.baseflumine.BaseFlumine.info")
@mock.patch("flumine.baseflumine.BaseFlumine.log_control")
def test__process_close_market_closed_paper(self, mock_log_control, mock_info):
self.base_flumine.client.paper_trade = True
mock_strategy = mock.Mock()
mock_strategy.stream_ids = [1, 2, 3]
self.base_flumine.strategies = [mock_strategy]
mock_market = mock.Mock(closed=False, elapsed_seconds_closed=None)
mock_market.market_book.streaming_unique_id = 2
self.base_flumine.markets._markets = {
"1.23": mock_market,
"4.56": mock.Mock(market_id="4.56", closed=True, elapsed_seconds_closed=25),
"7.89": mock.Mock(
market_id="7.89", closed=True, elapsed_seconds_closed=3601
),
"1.01": mock.Mock(
market_id="1.01", closed=False, elapsed_seconds_closed=3601
),
}
mock_event = mock.Mock()
mock_market_book = mock.Mock(market_id="1.23")
mock_event.event = mock_market_book
self.base_flumine._process_close_market(mock_event)
self.assertEqual(len(self.base_flumine.markets._markets), 4)

@mock.patch("flumine.baseflumine.events")
@mock.patch("flumine.baseflumine.BaseFlumine.log_control")
@mock.patch("flumine.baseflumine.BaseFlumine.info")
Expand Down

0 comments on commit 5fd4940

Please sign in to comment.