Repository: liampauling/flumine
Pull request #397 (2021-03-19 11:16:38)

Market recording mode
- Parameter to run flumine in Market Recording Mode, removing poll_account_balance and poll_market_closure calls since they do not add information to the recorded data.


Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index 9086b95..284be1b 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -3,14 +3,6 @@
 Release History
 ---------------
 
-1.17.13 (2021-03-22)
-+++++++++++++++++++
-
-**Improvements**
-
-- Market recorder mode added to client (@jorgegarcia7)
-- Further execution logging (trying to find time)
-
 1.17.12 (2021-03-15)
 +++++++++++++++++++
 
diff --git a/flumine/__version__.py b/flumine/__version__.py
index eabb4ef..6842e14 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.17.13"
+__version__ = "1.17.12"
 __author__ = "Liam Pauling"
 __license__ = "MIT"
diff --git a/flumine/clients/baseclient.py b/flumine/clients/baseclient.py
index a6d8111..0806873 100644
--- a/flumine/clients/baseclient.py
+++ b/flumine/clients/baseclient.py
@@ -27,6 +27,7 @@ class BaseClient:
         best_price_execution: bool = True,
         min_bet_validation: bool = True,
         paper_trade: bool = False,
+        market_recording_mode: bool = False,
     ):
         self.id = id_ or create_short_uuid()
         self.betting_client = betting_client
@@ -38,6 +39,7 @@ class BaseClient:
         self.best_price_execution = best_price_execution
         self.min_bet_validation = min_bet_validation  # used in OrderValidation control
         self.paper_trade = paper_trade
+        self.market_recording_mode = market_recording_mode
 
         self.account_details = None
         self.account_funds = None
diff --git a/flumine/execution/baseexecution.py b/flumine/execution/baseexecution.py
index ec761be..18b3aaf 100644
--- a/flumine/execution/baseexecution.py
+++ b/flumine/execution/baseexecution.py
@@ -39,15 +39,7 @@ class BaseExecution:
             func = self.execute_replace
         else:
             raise NotImplementedError()
-        logger.info(
-            "Thread pool submit",
-            extra={
-                "trading_function": func.__name__,
-                "session": http_session,
-                "latency": round(order_package.elapsed_seconds, 3),
-                "order_package": order_package.info,
-            },
-        )
+
         self._thread_pool.submit(func, order_package, http_session)
 
     def execute_place(
diff --git a/flumine/flumine.py b/flumine/flumine.py
index a6388d0..1f75f5c 100644
--- a/flumine/flumine.py
+++ b/flumine/flumine.py
@@ -55,14 +55,6 @@ class Flumine(BaseFlumine):
                 self, function=worker.keep_alive, interval=ka_interval
             )
         )
-        self.add_worker(
-            worker.BackgroundWorker(
-                self,
-                function=worker.poll_account_balance,
-                interval=120,
-                start_delay=10,  # wait for login
-            )
-        )
         self.add_worker(
             worker.BackgroundWorker(
                 self,
@@ -71,14 +63,23 @@ class Flumine(BaseFlumine):
                 start_delay=10,  # wait for streams to populate
             )
         )
-        self.add_worker(
-            worker.BackgroundWorker(
-                self,
-                function=worker.poll_market_closure,
-                interval=60,
-                start_delay=10,  # wait for login
+        if self.client.market_recording_mode is False:
+            self.add_worker(
+                worker.BackgroundWorker(
+                    self,
+                    function=worker.poll_account_balance,
+                    interval=120,
+                    start_delay=10,  # wait for login
+                )
+            )
+            self.add_worker(
+                worker.BackgroundWorker(
+                    self,
+                    function=worker.poll_market_closure,
+                    interval=60,
+                    start_delay=10,  # wait for login
+                )
             )
-        )
 
     def __repr__(self) -> str:
         return "<Flumine>"


Test patch:
diff --git a/tests/test_flumine.py b/tests/test_flumine.py
index bf96950..8656147 100644
--- a/tests/test_flumine.py
+++ b/tests/test_flumine.py
@@ -63,6 +63,7 @@ class FlumineTest(unittest.TestCase):
     @mock.patch("flumine.Flumine.add_worker")
     def test__add_default_workers(self, mock_add_worker, mock_worker):
         self.mock_trading.betting_client.session_timeout = 1200
+        self.flumine.client.market_recording_mode = False
         self.flumine._add_default_workers()
         self.assertEqual(len(mock_add_worker.call_args_list), 4)
         self.assertEqual(
@@ -71,14 +72,14 @@ class FlumineTest(unittest.TestCase):
                 mock.call(self.flumine, function=worker.keep_alive, interval=600),
                 mock.call(
                     self.flumine,
-                    function=worker.poll_account_balance,
-                    interval=120,
+                    function=worker.poll_market_catalogue,
+                    interval=60,
                     start_delay=10,
                 ),
                 mock.call(
                     self.flumine,
-                    function=worker.poll_market_catalogue,
-                    interval=60,
+                    function=worker.poll_account_balance,
+                    interval=120,
                     start_delay=10,
                 ),
                 mock.call(