Skip to content

Commit

Permalink
Merge pull request #236 from liampauling/dev
Browse files Browse the repository at this point in the history
Move remove_markets logic to process_closed_markets (previously not c…
  • Loading branch information
liampauling committed Jul 17, 2020
2 parents e81bcce + 6a8d3ae commit 2d98219
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 34 deletions.
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ env:

jobs:
include:
- name: "Tests: python 3.5"
python: 3.5
script:
- coverage run --source=flumine setup.py test
- name: "Tests: python 3.6"
python: 3.6
script:
Expand Down
8 changes: 8 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
Release History
---------------

1.9.3 (2020-07-17)
+++++++++++++++++++

**Bug Fixes**

- Move remove_markets logic to process_closed_markets (previously not called if no orders)
- Travis remove py3.5

1.9.2 (2020-07-16)
+++++++++++++++++++

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Support for market and custom streaming data (order, score and custom polling da

[join slack group](https://betfairlightweight.herokuapp.com)

Currently tested on Python 3.5, 3.6, 3.7 and 3.8.
Currently tested on Python 3.6, 3.7 and 3.8.

## installation

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Support for market, order and custom streaming data.

[join slack group](https://betfairlightweight.herokuapp.com)

Currently tested on Python 3.5, 3.6, 3.7 and 3.8.
Currently tested on Python 3.6, 3.7 and 3.8.

## installation

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.9.2"
__version__ = "1.9.3"
__author__ = "Liam Pauling"
__license__ = "MIT"
18 changes: 9 additions & 9 deletions flumine/baseflumine.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,15 @@ def _process_close_market(self, event: events.CloseMarketEvent) -> None:
self.log_control(event)
logger.info("Market closed", extra={"market_id": market.market_id, **self.info})

# check for markets that have been closed for x seconds and remove
closed_markets = [
m
for m in self.markets
if m.closed and m.elapsed_seconds_closed and m.elapsed_seconds_closed > 3600
]
for market in closed_markets:
self._remove_market(market)

def _process_cleared_orders(self, event):
market_id = event.event.market_id
market = self.markets.markets.get(market_id)
Expand Down Expand Up @@ -258,15 +267,6 @@ def _process_cleared_markets(self, event: events.ClearedMarketsEvent):
},
)

# check for markets that have been closed for x seconds
closed_markets = [
m
for m in self.markets
if m.elapsed_seconds_closed and m.elapsed_seconds_closed > 3600
]
for market in closed_markets:
self._remove_market(market)

def _process_end_flumine(self) -> None:
for strategy in self.strategies:
strategy.finish()
Expand Down
47 changes: 29 additions & 18 deletions tests/test_baseflumine.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,9 @@ def test__process_close_market(self, mock_log_control, mock_info):
mock_strategy = mock.Mock()
mock_strategy.stream_ids = [1, 2, 3]
self.base_flumine.strategies = [mock_strategy]
mock_market = mock.Mock()
mock_market = mock.Mock(closed=False, elapsed_seconds_closed=None)
mock_market.market_book.streaming_unique_id = 2
mock_markets = mock.Mock()
mock_markets.markets = {"1.23": mock_market}
self.base_flumine.markets = mock_markets
self.base_flumine.markets._markets = {"1.23": mock_market}
mock_event = mock.Mock()
mock_market_book = mock.Mock(market_id="1.23")
mock_event.event = mock_market_book
Expand All @@ -212,17 +210,40 @@ def test__process_close_market(self, mock_log_control, mock_info):

@mock.patch("flumine.baseflumine.BaseFlumine.info")
def test__process_close_market_no_market(self, mock_info):
mock_market = mock.Mock()
mock_market = mock.Mock(closed=False, elapsed_seconds_closed=None)
mock_market.market_book.streaming_unique_id = 2
mock_markets = mock.Mock()
mock_markets.markets = {"1.23": mock_market}
self.base_flumine.markets = mock_markets
self.base_flumine.markets._markets = {"1.23": mock_market}
mock_event = mock.Mock()
mock_market_book = mock.Mock(market_id="1.45")
mock_event.event = mock_market_book
self.base_flumine._process_close_market(mock_event)
mock_market.close_market.assert_not_called()

@mock.patch("flumine.baseflumine.BaseFlumine.info")
@mock.patch("flumine.baseflumine.BaseFlumine.log_control")
def test__process_close_market_closed(self, mock_log_control, mock_info):
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), 3)

@mock.patch("flumine.baseflumine.events")
@mock.patch("flumine.baseflumine.BaseFlumine.log_control")
@mock.patch("flumine.baseflumine.BaseFlumine.info")
Expand Down Expand Up @@ -256,16 +277,6 @@ def test__process_cleared_markets(self):
mock_event.event.orders = []
self.base_flumine._process_cleared_markets(mock_event)

def test__process_cleared_markets_closed(self):
self.base_flumine.markets._markets = {
"123": mock.Mock(market_id="123", elapsed_seconds_closed=25),
"456": mock.Mock(market_id="456", elapsed_seconds_closed=3601),
}
mock_event = mock.Mock()
mock_event.event.orders = []
self.base_flumine._process_cleared_markets(mock_event)
self.assertEqual(len(self.base_flumine.markets._markets), 1)

def test__process_end_flumine(self):
self.base_flumine._process_end_flumine()

Expand Down

0 comments on commit 2d98219

Please sign in to comment.