Repository: liampauling/flumine
Pull request #504 (2021-09-19 08:44:35)

#499 bugfix on market recording
RaceCache optimisation


Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index bf3b6ab..01f0abf 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -3,6 +3,17 @@
 Release History
 ---------------
 
+1.20.1 (2021-09-19)
++++++++++++++++++++
+
+**Improvements**
+
+- RaceCache optimisation
+
+**Bug Fixes**
+
+- #499 bugfix on market recording
+
 1.20.0 (2021-09-17)
 +++++++++++++++++++
 
diff --git a/flumine/__version__.py b/flumine/__version__.py
index 54f464a..a8e896f 100644
--- a/flumine/__version__.py
+++ b/flumine/__version__.py
@@ -1,6 +1,6 @@
 __title__ = "flumine"
 __description__ = "Betfair trading framework"
 __url__ = "https://github.com/liampauling/flumine"
-__version__ = "1.20.0"
+__version__ = "1.20.1"
 __author__ = "Liam Pauling"
 __license__ = "MIT"
diff --git a/flumine/baseflumine.py b/flumine/baseflumine.py
index f8e3f5f..e4227b8 100644
--- a/flumine/baseflumine.py
+++ b/flumine/baseflumine.py
@@ -273,10 +273,10 @@ class BaseFlumine:
             )
             return
         # process market
-        market(market_book)
         if market.closed is False:
             market.close_market()
         if recorder is False:
+            market(market_book)
             market.blotter.process_closed_market(event.event)
 
         for strategy in self.strategies:
diff --git a/flumine/streams/historicalstream.py b/flumine/streams/historicalstream.py
index 44cef31..3fe0fa7 100644
--- a/flumine/streams/historicalstream.py
+++ b/flumine/streams/historicalstream.py
@@ -109,24 +109,21 @@ class FlumineRaceStream(RaceStream):
                 race_cache = RaceCache(
                     market_id, publish_time, race_id, self._lightweight
                 )
+                race_cache.start_time = create_time(publish_time, race_id)
                 self._caches[market_id] = race_cache
                 logger.info(
                     "[%s: %s]: %s added, %s markets in cache"
                     % (self, self.unique_id, market_id, len(self._caches))
                 )
-            race_cache.update_cache(update, publish_time)
-            self._updates_processed += 1
 
             # filter after start time
-            if not hasattr(race_cache, "start_time"):
-                race_cache.start_time = create_time(
-                    race_cache.publish_time, race_cache.race_id
-                )
             diff = (
                 race_cache.start_time
-                - datetime.datetime.utcfromtimestamp(race_cache.publish_time / 1e3)
+                - datetime.datetime.utcfromtimestamp(publish_time / 1e3)
             ).total_seconds()
             if diff <= 0:
+                race_cache.update_cache(update, publish_time)
+                self._updates_processed += 1
                 active = True
         return active
 


Test patch:
diff --git a/tests/test_baseflumine.py b/tests/test_baseflumine.py
index f77b701..653565a 100644
--- a/tests/test_baseflumine.py
+++ b/tests/test_baseflumine.py
@@ -254,6 +254,7 @@ class BaseFlumineTest(unittest.TestCase):
             mock_market, mock_market_book
         )
         mock_log_control.assert_called_with(mock_event)
+        mock_market.assert_not_called()
 
     @mock.patch("flumine.baseflumine.BaseFlumine.info")
     def test__process_close_market_no_market(self, mock_info):
diff --git a/tests/test_streams.py b/tests/test_streams.py
index c33a7a7..af5e90f 100644
--- a/tests/test_streams.py
+++ b/tests/test_streams.py
@@ -811,7 +811,7 @@ class TestFlumineRaceStream(unittest.TestCase):
             )
         )
         self.assertEqual(len(self.stream._caches), 1)
-        self.assertEqual(self.stream._updates_processed, 1)
+        self.assertEqual(self.stream._updates_processed, 0)
         mock_create_time.assert_called_with(1234, "13.10")