Repository: liampauling/flumine
Pull request #343 (2020-12-05 09:10:24)

#342 handle market/limit on close order types where there is no size


Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index 332624e..12b7c01 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -3,18 +3,6 @@
 Release History
 ---------------
 
-1.14.13 (2020-12-05)
-+++++++++++++++++++
-
-**Improvements**
-
-- Backtest market catalogue middleware example (@lunswor)
-- #344 Initial work on improving calls when subscribed to 5k+ markets
-
-**Bug Fixes**
-
-- #342 market/limit on close order size remaining bug
-
 1.14.12 (2020-11-28)
 +++++++++++++++++++
 
diff --git a/flumine/__version__.py b/flumine/__version__.py
index 4889a40..4101cdd 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.14.13"
+__version__ = "1.14.12"
 __author__ = "Liam Pauling"
 __license__ = "MIT"
diff --git a/flumine/order/order.py b/flumine/order/order.py
index 27ca471..36a95f7 100644
--- a/flumine/order/order.py
+++ b/flumine/order/order.py
@@ -390,10 +390,15 @@ class BetfairOrder(BaseOrder):
         try:
             return self.current_order.size_remaining or 0.0
         except AttributeError:
-            if self.size_matched > 0:  # placeResponse does not include sizeRemaining
-                return round(self.order_type.size - self.size_matched, 2)
+            if self.order_type.ORDER_TYPE == OrderTypes.LIMIT:
+                if (
+                    self.size_matched > 0
+                ):  # placeResponse does not include sizeRemaining
+                    return round(self.order_type.size - self.size_matched, 2)
+                else:
+                    return self.order_type.size
             else:
-                return self.order_type.size
+                return self.order_type.liability
 
     @property
     def size_cancelled(self) -> float:


Test patch:
diff --git a/tests/test_order.py b/tests/test_order.py
index b2f96be..5c6b0e9 100644
--- a/tests/test_order.py
+++ b/tests/test_order.py
@@ -423,6 +423,7 @@ class BetfairOrderTest(unittest.TestCase):
         self.assertEqual(self.order.size_matched, mock_current_order.size_matched)
 
     def test_size_remaining(self):
+        self.mock_order_type.ORDER_TYPE = OrderTypes.LIMIT
         self.mock_order_type.size = 0
         self.assertEqual(self.order.size_remaining, 0)
         self.mock_order_type.size = 10
@@ -431,6 +432,7 @@ class BetfairOrderTest(unittest.TestCase):
         self.assertEqual(self.order.size_remaining, mock_current_order.size_remaining)
 
     def test_size_remaining_missing(self):
+        self.mock_order_type.ORDER_TYPE = OrderTypes.LIMIT
         self.mock_order_type.size = 2.51
         self.assertEqual(self.order.size_remaining, 2.51)
 
@@ -439,10 +441,17 @@ class BetfairOrderTest(unittest.TestCase):
         new_callable=mock.PropertyMock,
     )
     def test_size_remaining_missing_partial_match(self, mock_size_matched):
+        self.mock_order_type.ORDER_TYPE = OrderTypes.LIMIT
         mock_size_matched.return_value = 2
         self.mock_order_type.size = 10
         self.assertEqual(self.order.size_remaining, 8)
 
+    def test_size_remaining_market_on_close(self):
+        self.mock_order_type.ORDER_TYPE = OrderTypes.MARKET_ON_CLOSE
+        self.mock_order_type.size = ValueError
+        self.order.responses.current_order = None
+        self.assertEqual(self.order.size_remaining, self.mock_order_type.liability)
+
     def test_size_cancelled(self):
         self.assertEqual(self.order.size_cancelled, 0)
         mock_current_order = mock.Mock(size_cancelled=10)