Repository: liampauling/flumine
Pull request #206 (2020-06-08 07:09:44)

recorder example updated


Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index 7f7b70a..d714411 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -3,6 +3,15 @@
 Release History
 ---------------
 
+1.6.4 (2020-06-08)
++++++++++++++++++++
+
+**Improvements**
+
+- Client passed in AccountBalance event
+- PublishTime added to order (MarketBook)
+- GH Actions fixed
+
 1.6.3 (2020-06-03)
 +++++++++++++++++++
 
diff --git a/examples/marketrecorder.py b/examples/marketrecorder.py
index e593b85..ba1024d 100644
--- a/examples/marketrecorder.py
+++ b/examples/marketrecorder.py
@@ -5,7 +5,7 @@ from pythonjsonlogger import jsonlogger
 
 from flumine import Flumine, clients
 from flumine.streams.datastream import DataStream
-from strategies.marketrecorder import S3MarketRecorder
+from strategies.marketrecorder import MarketRecorder
 
 logger = logging.getLogger()
 
@@ -22,22 +22,13 @@ client = clients.BetfairClient(trading)
 
 framework = Flumine(client=client)
 
-strategy = S3MarketRecorder(
+strategy = MarketRecorder(
     name="WIN",
     market_filter=betfairlightweight.filters.streaming_market_filter(
-        event_type_ids=["7"],
-        country_codes=["GB", "IE"],
-        market_types=["WIN"],
-        # market_ids=["1.169056942"],
-        # event_ids=[29671376]
+        event_type_ids=["7"], country_codes=["GB", "IE"], market_types=["WIN"],
     ),
     stream_class=DataStream,
-    context={
-        "local_dir": "/tmp",
-        "bucket": "fluminetest",
-        "force_update": False,
-        "remove_file": True,
-    },
+    context={"local_dir": "/tmp", "force_update": False, "remove_file": True,},
 )
 
 framework.add_strategy(strategy)
diff --git a/flumine/__version__.py b/flumine/__version__.py
index 709bed4..facafdb 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.6.3"
+__version__ = "1.6.4"
 __author__ = "Liam Pauling"
 __license__ = "MIT"
diff --git a/flumine/config.py b/flumine/config.py
index 122ba06..6736fae 100644
--- a/flumine/config.py
+++ b/flumine/config.py
@@ -3,6 +3,8 @@ import socket
 
 simulated = False
 
+instance_id = None  # instance id (e.g. AWS ec2 instanceId)
+
 hostname = socket.gethostname()[
     :15
 ]  # ie. docker container id (used as order customerStrategyRefs)
diff --git a/flumine/markets/market.py b/flumine/markets/market.py
index c9d2d88..a99c92f 100644
--- a/flumine/markets/market.py
+++ b/flumine/markets/market.py
@@ -35,7 +35,7 @@ class Market:
 
     # order
     def place_order(self, order, execute: bool = True) -> None:
-        order.place()
+        order.place(self.market_book.publish_time)
         if order.id not in self.blotter:
             self.blotter[order.id] = order
             self.flumine.log_control(events.TradeEvent(order.trade))  # todo dupes?
diff --git a/flumine/order/order.py b/flumine/order/order.py
index 75eae67..d94da83 100644
--- a/flumine/order/order.py
+++ b/flumine/order/order.py
@@ -55,6 +55,7 @@ class BaseOrder:
         self.update_data = {}  # stores cancel/update/replace data
         self.responses = Responses()  # raw api responses
         self.simulated = Simulated(self)  # used in simulated execution
+        self.publish_time = None  # marketBook.publish_time
 
     # status
     def _update_status(self, status: OrderStatus) -> None:
@@ -95,7 +96,7 @@ class BaseOrder:
         self.update_data.clear()
 
     # updates
-    def place(self) -> None:
+    def place(self, publish_time: int) -> None:
         raise NotImplementedError
 
     def cancel(self, size_reduction: float = None) -> None:
@@ -208,7 +209,8 @@ class BetfairOrder(BaseOrder):
     EXCHANGE = ExchangeType.BETFAIR
 
     # updates
-    def place(self) -> None:
+    def place(self, publish_time: int) -> None:
+        self.publish_time = publish_time
         self.placing()
 
     def cancel(self, size_reduction: float = None) -> None:
diff --git a/flumine/worker.py b/flumine/worker.py
index 2e3e893..2531062 100644
--- a/flumine/worker.py
+++ b/flumine/worker.py
@@ -130,7 +130,7 @@ def poll_account_balance(context: dict, flumine) -> None:
     client = flumine.client
     client.update_account_details()
     if client.account_funds:
-        flumine.log_control(events.BalanceEvent(client.account_funds))
+        flumine.log_control(events.BalanceEvent(client))
 
 
 def poll_cleared_orders(context: dict, flumine) -> None:
@@ -207,8 +207,8 @@ def _get_cleared_market(flumine, betting_client, market_id: str) -> bool:
         return False
 
     if cleared_markets.orders:
-        flumine.log_control(events.ClearedMarketsEvent(cleared_markets))
         flumine.handler_queue.put(events.ClearedMarketsEvent(cleared_markets))
+        flumine.log_control(events.ClearedMarketsEvent(cleared_markets))
         return True
     else:
         return False


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 79d1968..125e2d0 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -10,7 +10,7 @@ jobs:
         python-version: [3.6, 3.7, 3.8]
 
     steps:
-    - uses: actions/checkout@v1
+    - uses: actions/checkout@v2
 
     - name: Set up Python ${{ matrix.python-version }}
       uses: actions/setup-python@v1
@@ -45,7 +45,7 @@ jobs:
     if: github.ref == 'refs/heads/master'
 
     steps:
-    - uses: actions/checkout@v1
+    - uses: actions/checkout@v2
 
     - name: Set up Python 3.7
       uses: actions/setup-python@v1
diff --git a/tests/test_markets.py b/tests/test_markets.py
index 2dd7c17..7e4a37c 100644
--- a/tests/test_markets.py
+++ b/tests/test_markets.py
@@ -123,7 +123,7 @@ class MarketTest(unittest.TestCase):
         mock_order = mock.Mock()
         mock_order.id = "123"
         self.market.place_order(mock_order)
-        mock_order.place.assert_called_with()
+        mock_order.place.assert_called_with(self.market.market_book.publish_time)
         self.assertEqual(self.market.blotter.pending_place, [mock_order])
         self.mock_flumine.log_control.assert_called_with(mock_events.OrderEvent())
 
@@ -132,7 +132,7 @@ class MarketTest(unittest.TestCase):
         mock_order = mock.Mock()
         mock_order.id = "123"
         self.market.place_order(mock_order, execute=False)
-        mock_order.place.assert_called_with()
+        mock_order.place.assert_called_with(self.market.market_book.publish_time)
         self.assertEqual(self.market.blotter.pending_place, [])
         self.mock_flumine.log_control.assert_called_with(mock_events.OrderEvent())
 
diff --git a/tests/test_order.py b/tests/test_order.py
index eafa766..8594152 100644
--- a/tests/test_order.py
+++ b/tests/test_order.py
@@ -30,6 +30,7 @@ class BaseOrderTest(unittest.TestCase):
         self.assertIsNone(self.order.bet_id)
         self.assertIsNone(self.order.EXCHANGE)
         self.assertEqual(self.order.update_data, {})
+        self.assertIsNone(self.order.publish_time)
 
     def test__update_status(self):
         self.order._update_status(OrderStatus.EXECUTION_COMPLETE)
@@ -93,7 +94,7 @@ class BaseOrderTest(unittest.TestCase):
 
     def test_place(self):
         with self.assertRaises(NotImplementedError):
-            self.order.place()
+            self.order.place(123)
 
     def test_cancel(self):
         with self.assertRaises(NotImplementedError):
@@ -217,8 +218,9 @@ class BetfairOrderTest(unittest.TestCase):
 
     @mock.patch("flumine.order.order.BetfairOrder.placing")
     def test_place(self, mock_placing):
-        self.order.place()
+        self.order.place(123)
         mock_placing.assert_called_with()
+        self.assertEqual(self.order.publish_time, 123)
 
     @mock.patch(
         "flumine.order.order.BetfairOrder.size_remaining",