Repository: liampauling/flumine
Pull request #488 (2021-09-06 21:09:00)

Renaming hostname to customer_strategy_ref
Renaming `hostname` to `customer_strategy_ref`, which makes intent more explicit.


Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index b4a3488..1dcbdf5 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -6,6 +6,15 @@ Release History
 1.19.12 (2021-08-27)
 +++++++++++++++++++
 
+** Improvements**
+
+ - Renamed config.hostname to config.customer_strategy_ref. This makes the use of the variable more explicit.
+ - WARNING: This change will affect users who set config.hostname. From this version onwards, they should set
+            config.customer_strategy_ref.
+
+1.19.12 (2021-08-27)
++++++++++++++++++++
+
 **Bug Fixes**
 
 - Prevent duplicate EC calls when backtesting
diff --git a/docs/advanced.md b/docs/advanced.md
index fd261ed..e6d98eb 100644
--- a/docs/advanced.md
+++ b/docs/advanced.md
@@ -88,46 +88,46 @@ Updated to True when backtesting or paper trading
 
 Store server id or similar (e.g. AWS ec2 instanceId)
 
-#### hostname
+### hostname
 
 Used as customerStrategyRefs so that only orders created by the running instance are returned.
 
-#### process_id
+### process_id
 
 OS process id of running application.
 
-#### current_time
+### current_time
 
 Used for backtesting
 
-#### raise_errors
+### raise_errors
 
 Raises errors on strategy functions, see [Error Handling](/advanced/#error-handling)
 
-#### max_execution_workers
+### max_execution_workers
 
 Max number of workers in execution thread pool
 
-#### async_place_orders
+### async_place_orders
 
 Place orders sent with place orders flag, prevents waiting for bet delay
 
-#### place_latency
+### place_latency
 
 Place latency used for backtesting / simulation execution
 
-#### cancel_latency
+### cancel_latency
 
 Cancel latency used for backtesting / simulation execution
 
-#### update_latency
+### update_latency
 
 Update latency used for backtesting / simulation execution
 
-#### replace_latency
+### replace_latency
 
 Replace latency used for backtesting / simulation execution
 
-#### order_sep 
+### order_sep 
 
 customer_order_ref separator
diff --git a/docs/markets.md b/docs/markets.md
index a33cd06..17fb82d 100644
--- a/docs/markets.md
+++ b/docs/markets.md
@@ -89,9 +89,3 @@ class CustomMiddleware(Middleware):
     def remove_market(self, market) -> None:
         print("market {0} removed".format(market.market_id))
 ```
-
-The above middleware can then be added to the framework:
-
-```python
-framework.add_logging_control(CustomMiddleware())
-```
diff --git a/docs/quickstart.md b/docs/quickstart.md
index 2211a77..1efc173 100644
--- a/docs/quickstart.md
+++ b/docs/quickstart.md
@@ -228,7 +228,7 @@ When backtesting you can filter markets to be processed by using the `market_typ
 
 ```python
 strategy = ExampleStrategy(
-    market_filter={"markets": [..], "market_types": ["MATCH_ODDS"]}
+    market_filter={"markets": [..], "market_type": ["MATCH_ODDS"]}
 )
 ```
 
diff --git a/examples/middleware/orders.py b/examples/middleware/orders.py
index f1e82f6..e2d8100 100644
--- a/examples/middleware/orders.py
+++ b/examples/middleware/orders.py
@@ -20,7 +20,7 @@ class OrdersMiddleware(Middleware):
 
     def add_market(self, market) -> None:
         resp = self.flumine.client.betting_client.betting.list_current_orders(
-            customer_strategy_refs=[config.hostname],
+            customer_strategy_refs=[config.customer_strategy_ref],
             order_projection="EXECUTION_COMPLETE",
         )
         for current_order in resp.orders:
diff --git a/flumine/config.py b/flumine/config.py
index 013f0de..ffedfbc 100644
--- a/flumine/config.py
+++ b/flumine/config.py
@@ -5,10 +5,12 @@ simulated = False
 
 instance_id = None  # instance id (e.g. AWS ec2 instanceId)
 
-hostname = socket.gethostname()[
+customer_strategy_ref = socket.gethostname()[
     :15
 ]  # ie. docker container id (used as order customerStrategyRefs)
 
+hostname = customer_strategy_ref
+
 process_id = os.getpid()  # process id of app
 
 current_time = None  # used for backtesting
diff --git a/flumine/markets/market.py b/flumine/markets/market.py
index fea8d13..f211e8e 100644
--- a/flumine/markets/market.py
+++ b/flumine/markets/market.py
@@ -181,7 +181,7 @@ class Market:
             "marketId": self.market_id,
             "eventId": self.event_id,
             "eventTypeId": self.event_type_id,
-            "customerStrategyRef": config.hostname,
+            "customerStrategyRef": config.customer_strategy_ref,
             "lastMatchedDate": None,
             "placedDate": None,
             "settledDate": None,
diff --git a/flumine/order/orderpackage.py b/flumine/order/orderpackage.py
index ebf8cad..a318125 100644
--- a/flumine/order/orderpackage.py
+++ b/flumine/order/orderpackage.py
@@ -45,7 +45,7 @@ class BaseOrderPackage(BaseEvent):
         self.package_type = package_type
         self.async_ = async_
         self._market_version = market_version
-        self.customer_strategy_ref = config.hostname
+        self.customer_strategy_ref = config.customer_strategy_ref
         self._retry = True
         self._max_retries = 3  # will retry 3 times
         self._retry_count = 0
diff --git a/flumine/streams/datastream.py b/flumine/streams/datastream.py
index 537e807..789b1a7 100644
--- a/flumine/streams/datastream.py
+++ b/flumine/streams/datastream.py
@@ -162,7 +162,7 @@ class OrderDataStream(DataStream):
             "Starting OrderDataStream {0}".format(self.stream_id),
             extra={
                 "stream_id": self.stream_id,
-                "customer_strategy_refs": config.hostname,
+                "customer_strategy_refs": config.customer_strategy_ref,
                 "conflate_ms": self.conflate_ms,
                 "streaming_timeout": self.streaming_timeout,
             },
@@ -173,7 +173,7 @@ class OrderDataStream(DataStream):
         try:
             self.stream_id = self._stream.subscribe_to_orders(
                 order_filter=filters.streaming_order_filter(
-                    customer_strategy_refs=[config.hostname],
+                    customer_strategy_refs=[config.customer_strategy_ref],
                     partition_matched_by_strategy_ref=True,
                     include_overall_position=False,
                 ),
diff --git a/flumine/streams/orderstream.py b/flumine/streams/orderstream.py
index 62aa140..4cc3537 100644
--- a/flumine/streams/orderstream.py
+++ b/flumine/streams/orderstream.py
@@ -22,7 +22,7 @@ class OrderStream(BaseStream):
             "Starting OrderStream {0}".format(self.stream_id),
             extra={
                 "stream_id": self.stream_id,
-                "customer_strategy_refs": config.hostname,
+                "customer_strategy_refs": config.customer_strategy_ref,
                 "conflate_ms": self.conflate_ms,
                 "streaming_timeout": self.streaming_timeout,
             },
@@ -39,7 +39,7 @@ class OrderStream(BaseStream):
         try:
             self.stream_id = self._stream.subscribe_to_orders(
                 order_filter=filters.streaming_order_filter(
-                    customer_strategy_refs=[config.hostname],
+                    customer_strategy_refs=[config.customer_strategy_ref],
                     partition_matched_by_strategy_ref=True,
                     include_overall_position=False,
                 ),
diff --git a/flumine/worker.py b/flumine/worker.py
index 91c9b13..bd669d1 100644
--- a/flumine/worker.py
+++ b/flumine/worker.py
@@ -190,7 +190,7 @@ def _get_cleared_orders(flumine, betting_client, market_id: str) -> bool:
                 bet_status="SETTLED",
                 from_record=from_record,
                 market_ids=[market_id],
-                customer_strategy_refs=[config.hostname],
+                customer_strategy_refs=[config.customer_strategy_ref],
             )
         except exceptions.StatusCodeError as e:
             # log as warning to prevent duplicate logs on betfair meltdown
@@ -228,7 +228,7 @@ def _get_cleared_market(flumine, betting_client, market_id: str) -> bool:
         cleared_markets = betting_client.betting.list_cleared_orders(
             bet_status="SETTLED",
             market_ids=[market_id],
-            customer_strategy_refs=[config.hostname],
+            customer_strategy_refs=[config.customer_strategy_ref],
             group_by="MARKET",
         )
     except exceptions.StatusCodeError as e:


Test patch:
diff --git a/examples/controls/backtestloggingcontrol.py b/examples/controls/backtestloggingcontrol.py
index 4fc0f5d..ff95785 100644
--- a/examples/controls/backtestloggingcontrol.py
+++ b/examples/controls/backtestloggingcontrol.py
@@ -20,8 +20,7 @@ FIELDNAMES = [
     "elapsed_seconds_executable",
     "order_status",
     "market_note",
-    "trade_notes",
-    "order_notes",
+    "notes",
 ]
 
 
@@ -58,8 +57,7 @@ class BacktestLoggingControl(LoggingControl):
                         "elapsed_seconds_executable": order.elapsed_seconds_executable,
                         "order_status": order.status.value,
                         "market_note": order.trade.market_notes,
-                        "trade_notes": order.trade.notes_str,
-                        "order_notes": order.notes_str,
+                        "notes": order.trade.notes_str,
                     }
                     csv_writer = csv.DictWriter(m, delimiter=",", fieldnames=FIELDNAMES)
                     csv_writer.writerow(order_data)
diff --git a/tests/test_config.py b/tests/test_config.py
index 1c3b494..0c5cfd6 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -6,7 +6,7 @@ from flumine import config
 class ConfigTest(unittest.TestCase):
     def test_init(self):
         self.assertFalse(config.simulated)
-        self.assertIsInstance(config.hostname, str)
+        self.assertIsInstance(config.customer_strategy_ref, str)
         self.assertIsInstance(config.process_id, int)
         self.assertIsNone(config.current_time)
         self.assertFalse(config.raise_errors)
diff --git a/tests/test_markets.py b/tests/test_markets.py
index e296875..6190b19 100644
--- a/tests/test_markets.py
+++ b/tests/test_markets.py
@@ -328,7 +328,7 @@ class MarketTest(unittest.TestCase):
                 "betCount": 0,
                 "betOutcome": "WON",
                 "commission": 0.0,
-                "customerStrategyRef": config.hostname,
+                "customerStrategyRef": config.customer_strategy_ref,
                 "eventId": mock_event_id,
                 "eventTypeId": mock_event_type_id,
                 "lastMatchedDate": None,
diff --git a/tests/test_worker.py b/tests/test_worker.py
index 2ec64e4..78bc23f 100644
--- a/tests/test_worker.py
+++ b/tests/test_worker.py
@@ -236,7 +236,7 @@ class WorkersTest(unittest.TestCase):
             bet_status="SETTLED",
             market_ids=["1.23"],
             from_record=0,
-            customer_strategy_refs=[mock_config.hostname],
+            customer_strategy_refs=[mock_config.customer_strategy_ref],
         )
         mock_flumine.log_control.assert_called_with(mock_events.ClearedOrdersEvent())
         mock_flumine.handler_queue.put.assert_called_with(
@@ -258,7 +258,7 @@ class WorkersTest(unittest.TestCase):
             bet_status="SETTLED",
             market_ids=["1.23"],
             from_record=0,
-            customer_strategy_refs=[mock_config.hostname],
+            customer_strategy_refs=[mock_config.customer_strategy_ref],
         )
 
     @mock.patch("flumine.worker.config")
@@ -274,7 +274,7 @@ class WorkersTest(unittest.TestCase):
             bet_status="SETTLED",
             market_ids=["1.23"],
             from_record=0,
-            customer_strategy_refs=[mock_config.hostname],
+            customer_strategy_refs=[mock_config.customer_strategy_ref],
         )
 
     @mock.patch("flumine.worker.config")
@@ -294,7 +294,7 @@ class WorkersTest(unittest.TestCase):
             bet_status="SETTLED",
             market_ids=["1.23"],
             group_by="MARKET",
-            customer_strategy_refs=[mock_config.hostname],
+            customer_strategy_refs=[mock_config.customer_strategy_ref],
         )
         mock_flumine.handler_queue.put.assert_called_with(
             mock_events.ClearedMarketsEvent()
@@ -316,7 +316,7 @@ class WorkersTest(unittest.TestCase):
             bet_status="SETTLED",
             market_ids=["1.23"],
             group_by="MARKET",
-            customer_strategy_refs=[mock_config.hostname],
+            customer_strategy_refs=[mock_config.customer_strategy_ref],
         )
 
     @mock.patch("flumine.worker.config")
@@ -334,7 +334,7 @@ class WorkersTest(unittest.TestCase):
             bet_status="SETTLED",
             market_ids=["1.23"],
             group_by="MARKET",
-            customer_strategy_refs=[mock_config.hostname],
+            customer_strategy_refs=[mock_config.customer_strategy_ref],
         )
 
     @mock.patch("flumine.worker.config")
@@ -350,5 +350,5 @@ class WorkersTest(unittest.TestCase):
             bet_status="SETTLED",
             market_ids=["1.23"],
             group_by="MARKET",
-            customer_strategy_refs=[mock_config.hostname],
+            customer_strategy_refs=[mock_config.customer_strategy_ref],
         )