Repository: liampauling/flumine
Pull request #395 (2021-03-12 11:48:39)

order context added
Prevent duplicate order logging control calls


Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index 0354133..f599ee4 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -3,6 +3,17 @@
 Release History
 ---------------
 
+1.17.11 (2021-03-12)
++++++++++++++++++++
+
+**Improvements**
+
+- order context added
+
+**Bug Fixes**
+
+- Prevent duplicate order logging control calls
+
 1.17.10 (2021-03-12)
 +++++++++++++++++++
 
diff --git a/flumine/__version__.py b/flumine/__version__.py
index 3e092d1..b34c143 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.10"
+__version__ = "1.17.11"
 __author__ = "Liam Pauling"
 __license__ = "MIT"
diff --git a/flumine/order/order.py b/flumine/order/order.py
index bcc4821..f09f6bb 100644
--- a/flumine/order/order.py
+++ b/flumine/order/order.py
@@ -49,7 +49,8 @@ class BaseOrder:
         side: str,
         order_type: Union[LimitOrder, LimitOnCloseOrder, MarketOnCloseOrder],
         handicap: float = 0,
-        sep="-",
+        sep: str = "-",
+        context: dict = None,
     ):
         self.id = str(uuid.uuid1().time)  # 18 char str used as unique customerOrderRef
         self.trade = trade
@@ -62,7 +63,7 @@ class BaseOrder:
         self.status = None
         self.status_log = []
         self.violation_msg = None
-        self.context = {}  # store order specific notes/triggers
+        self.context = context or {}  # store order specific notes/triggers
 
         self.bet_id = None
         self.update_data = {}  # stores cancel/update/replace data
diff --git a/flumine/order/process.py b/flumine/order/process.py
index 087dd3f..f4ae225 100644
--- a/flumine/order/process.py
+++ b/flumine/order/process.py
@@ -1,5 +1,6 @@
 import logging
 
+from .. import config
 from ..markets.markets import Markets
 from ..order.order import BaseOrder, OrderStatus, OrderTypes
 from ..order.trade import Trade
@@ -57,7 +58,9 @@ def process_current_orders(
                     continue
 
             if (
-                order.bet_id is None and current_order.bet_id
+                config.async_place_orders
+                and order.bet_id is None
+                and current_order.bet_id
             ):  # async bet pending processing
                 order.bet_id = current_order.bet_id
                 log_control(OrderEvent(order))


Test patch:
diff --git a/tests/test_order.py b/tests/test_order.py
index b8b54f8..dfcf732 100644
--- a/tests/test_order.py
+++ b/tests/test_order.py
@@ -21,7 +21,9 @@ class BaseOrderTest(unittest.TestCase):
             client=mock_client, market_id="1.1", selection_id=123, info={}
         )
         self.mock_order_type = mock.Mock(info={})
-        self.order = BaseOrder(self.mock_trade, "BACK", self.mock_order_type, 1)
+        self.order = BaseOrder(
+            self.mock_trade, "BACK", self.mock_order_type, 1, context={1: 2}
+        )
 
     def test_init(self):
         self.assertIsNotNone(self.order.id)
@@ -37,7 +39,7 @@ class BaseOrderTest(unittest.TestCase):
         self.assertIsNone(self.order.status)
         self.assertEqual(self.order.status_log, [])
         self.assertIsNone(self.order.violation_msg)
-        self.assertEqual(self.order.context, {})
+        self.assertEqual(self.order.context, {1: 2})
         self.assertIsNone(self.order.bet_id)
         self.assertIsNone(self.order.EXCHANGE)
         self.assertEqual(self.order.update_data, {})