Repository: liampauling/flumine
Pull request #177 (2020-05-28 18:11:17)

missing inheritance


Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index 22511f9..7e34b00 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -3,6 +3,18 @@
 Release History
 ---------------
 
+1.5.5 (2020-05-29)
++++++++++++++++++++
+
+**Improvements**
+
+- Missing Middleware inheritance
+- get_sp added
+
+**Bug Fixes**
+
+- MarketCatalogue missing from Market when logged
+
 1.5.4 (2020-05-22)
 +++++++++++++++++++
 
diff --git a/flumine/__version__.py b/flumine/__version__.py
index 9e02207..3a260db 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.5.4"
+__version__ = "1.5.5"
 __author__ = "Liam Pauling"
 __license__ = "MIT"
diff --git a/flumine/baseflumine.py b/flumine/baseflumine.py
index 8dfd155..9332acd 100644
--- a/flumine/baseflumine.py
+++ b/flumine/baseflumine.py
@@ -164,11 +164,13 @@ class BaseFlumine:
             market = self.markets.markets.get(market_catalogue.market_id)
             if market:
                 if market.market_catalogue is None:
+                    market.market_catalogue = market_catalogue
                     self.log_control(events.MarketEvent(market))
                     logger.info(
                         "Updated marketCatalogue for {0}".format(market.market_id)
                     )
-                market.market_catalogue = market_catalogue
+                else:
+                    market.market_catalogue = market_catalogue
 
     def _process_current_orders(self, event: events.CurrentOrdersEvent) -> None:
         process_current_orders(self.markets, self.strategies, event)  # update state
diff --git a/flumine/markets/middleware.py b/flumine/markets/middleware.py
index fb01511..de95269 100644
--- a/flumine/markets/middleware.py
+++ b/flumine/markets/middleware.py
@@ -1,6 +1,6 @@
 import logging
 from collections import defaultdict
-from betfairlightweight.resources.bettingresources import MarketBook, RunnerBook
+from betfairlightweight.resources.bettingresources import RunnerBook
 
 from ..order.order import OrderStatus
 
@@ -12,7 +12,7 @@ class Middleware:
         raise NotImplementedError
 
 
-class SimulatedMiddleware:
+class SimulatedMiddleware(Middleware):
     """
     Calculates matched amounts per runner
     to be used in simulated matching.
diff --git a/flumine/utils.py b/flumine/utils.py
index ba1b296..f920b3b 100644
--- a/flumine/utils.py
+++ b/flumine/utils.py
@@ -3,6 +3,7 @@ import logging
 import hashlib
 from typing import Optional, Tuple
 from decimal import Decimal
+from betfairlightweight.resources.bettingresources import RunnerBook
 
 logger = logging.getLogger(__name__)
 
@@ -92,6 +93,17 @@ def get_size(data: list, level: int) -> Optional[float]:
         return
 
 
+def get_sp(runner: RunnerBook) -> Optional[float]:
+    if isinstance(runner.sp, list):
+        return
+    elif runner.sp is None:
+        return
+    elif runner.sp.actual_sp == "NaN":
+        return
+    else:
+        return runner.sp.actual_sp
+
+
 def price_ticks_away(price: float, n_ticks: int) -> float:
     try:
         price_index = PRICES.index(as_dec(price))


Test patch:
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 59e3814..ef4f2d7 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -61,6 +61,18 @@ class UtilsTest(unittest.TestCase):
         )
         self.assertIsNone(utils.get_size([], 3))
 
+    def test_get_sp(self):
+        mock_runner = mock.Mock()
+        mock_runner.sp = []
+        self.assertIsNone(utils.get_sp(mock_runner))
+        mock_runner.sp = None
+        self.assertIsNone(utils.get_sp(mock_runner))
+        mock_runner = mock.Mock()
+        mock_runner.sp.actual_sp = "NaN"
+        self.assertIsNone(utils.get_sp(mock_runner))
+        mock_runner.sp.actual_sp = 12.2345
+        self.assertEqual(utils.get_sp(mock_runner), 12.2345)
+
     def test_price_ticks_away(self):
         self.assertEqual(utils.price_ticks_away(1.01, 1), 1.02)
         self.assertEqual(utils.price_ticks_away(1.01, 5), 1.06)