Repository: liampauling/flumine
Pull request #204 (2020-06-04 07:36:11)

#191
take III using v2 checkout


Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index 7f7b70a..860a60f 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -3,18 +3,6 @@
 Release History
 ---------------
 
-1.6.3 (2020-06-03)
-+++++++++++++++++++
-
-**Improvements**
-
-- #178 Client order stream disable/enable
-- #179 Info properties
-
-**Bug Fixes**
-
-- #191 missing git config
-
 1.6.2 (2020-06-03)
 +++++++++++++++++++
 
diff --git a/examples/marketrecorder.py b/examples/marketrecorder.py
index ba1024d..e593b85 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 MarketRecorder
+from strategies.marketrecorder import S3MarketRecorder
 
 logger = logging.getLogger()
 
@@ -22,13 +22,22 @@ client = clients.BetfairClient(trading)
 
 framework = Flumine(client=client)
 
-strategy = MarketRecorder(
+strategy = S3MarketRecorder(
     name="WIN",
     market_filter=betfairlightweight.filters.streaming_market_filter(
-        event_type_ids=["7"], country_codes=["GB", "IE"], market_types=["WIN"],
+        event_type_ids=["7"],
+        country_codes=["GB", "IE"],
+        market_types=["WIN"],
+        # market_ids=["1.169056942"],
+        # event_ids=[29671376]
     ),
     stream_class=DataStream,
-    context={"local_dir": "/tmp", "force_update": False, "remove_file": True,},
+    context={
+        "local_dir": "/tmp",
+        "bucket": "fluminetest",
+        "force_update": False,
+        "remove_file": True,
+    },
 )
 
 framework.add_strategy(strategy)
diff --git a/flumine/__version__.py b/flumine/__version__.py
index 709bed4..a0c94e1 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.2"
 __author__ = "Liam Pauling"
 __license__ = "MIT"
diff --git a/flumine/baseflumine.py b/flumine/baseflumine.py
index b59a3f5..fa526df 100644
--- a/flumine/baseflumine.py
+++ b/flumine/baseflumine.py
@@ -1,6 +1,5 @@
 import queue
 import logging
-import threading
 from typing import Type
 from betfairlightweight import resources
 
@@ -152,7 +151,7 @@ class BaseFlumine:
     ) -> Market:
         market = Market(self, market_id, market_book)
         self.markets.add_market(market_id, market)
-        logger.info("Adding: {0} to markets".format(market.market_id), extra=self.info)
+        logger.info("Adding: {0} to markets".format(market.market_id))
         return market
 
     def _process_raw_data(self, event: events.RawDataEvent) -> None:
@@ -214,15 +213,11 @@ class BaseFlumine:
 
         self.cleared_market_queue.put(market.market_id)
         self.log_control(event)
-        logger.info(
-            "Market removed", extra={"market_id": market.market_id, **self.info}
-        )
 
     def _process_cleared_orders(self, event):
         # todo update blotter?
         logger.info(
-            "Market closed and cleared",
-            extra={"market_id": event.event.market_id, **self.info},
+            "Market closed and cleared", extra={"market_id": event.event.market_id},
         )
 
     def _process_cleared_markets(self, event: events.ClearedMarketsEvent):
@@ -241,23 +236,8 @@ class BaseFlumine:
         for strategy in self.strategies:
             strategy.finish()
 
-    @property
-    def info(self) -> dict:
-        return {
-            "client": self.client.info,
-            "markets": {
-                "market_count": len(self.markets),
-                "open_market_count": len(self.markets.open_market_ids),
-                "live_orders": self.markets.live_orders,
-                "markets": [m.market_id for m in self.markets],
-            },
-            "streams": [s for s in self.streams],
-            "logging_controls": self._logging_controls,
-            "threads": threading.enumerate(),
-        }
-
     def __enter__(self):
-        logger.info("Starting flumine", extra=self.info)
+        logger.info("Starting flumine")
         # add execution to clients
         self.client.add_execution(self)
         # simulated
@@ -296,4 +276,4 @@ class BaseFlumine:
         # logout
         self.client.logout()
         self._running = False
-        logger.info("Exiting flumine", extra=self.info)
+        logger.info("Exiting flumine")
diff --git a/flumine/clients/baseclient.py b/flumine/clients/baseclient.py
index e5f2865..8a1aec1 100644
--- a/flumine/clients/baseclient.py
+++ b/flumine/clients/baseclient.py
@@ -22,7 +22,6 @@ class BaseClient:
         commission_base: float = DEFAULT_COMMISSION_BASE,
         interactive_login: bool = False,
         id_: str = None,
-        order_stream: bool = True,
     ):
         self.id = id_ or create_short_uuid()
         self.betting_client = betting_client
@@ -30,7 +29,6 @@ class BaseClient:
         self.capital_base = capital_base
         self.commission_base = commission_base
         self.interactive_login = interactive_login
-        self.order_stream = order_stream
 
         self.account_details = None
         self.account_funds = None
@@ -69,13 +67,3 @@ class BaseClient:
     @property
     def min_bsp_liability(self) -> Optional[float]:
         raise NotImplementedError
-
-    @property
-    def info(self) -> dict:
-        return {
-            "id": self.id,
-            "exchange": self.EXCHANGE.value if self.EXCHANGE else None,
-            "betting_client": self.betting_client,
-            "chargeable_transaction_count": self.chargeable_transaction_count,
-            "trading_controls": self.trading_controls,
-        }
diff --git a/flumine/config.py b/flumine/config.py
index 6736fae..122ba06 100644
--- a/flumine/config.py
+++ b/flumine/config.py
@@ -3,8 +3,6 @@ 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 a99c92f..c9d2d88 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(self.market_book.publish_time)
+        order.place()
         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 d94da83..75eae67 100644
--- a/flumine/order/order.py
+++ b/flumine/order/order.py
@@ -55,7 +55,6 @@ 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:
@@ -96,7 +95,7 @@ class BaseOrder:
         self.update_data.clear()
 
     # updates
-    def place(self, publish_time: int) -> None:
+    def place(self) -> None:
         raise NotImplementedError
 
     def cancel(self, size_reduction: float = None) -> None:
@@ -209,8 +208,7 @@ class BetfairOrder(BaseOrder):
     EXCHANGE = ExchangeType.BETFAIR
 
     # updates
-    def place(self, publish_time: int) -> None:
-        self.publish_time = publish_time
+    def place(self) -> None:
         self.placing()
 
     def cancel(self, size_reduction: float = None) -> None:
diff --git a/flumine/streams/streams.py b/flumine/streams/streams.py
index 98214d4..c453a59 100644
--- a/flumine/streams/streams.py
+++ b/flumine/streams/streams.py
@@ -31,10 +31,10 @@ class Streams:
             strategy.streams.append(stream)
 
     def add_client(self, client: BaseClient) -> None:
-        if client.order_stream:
-            # todo if paper_trade: add_simulated_order_stream()
-            if client.EXCHANGE == ExchangeType.BETFAIR:
-                self.add_order_stream(client)
+        if client.EXCHANGE == ExchangeType.SIMULATED:
+            self.add_simulated_order_stream()
+        elif client.EXCHANGE == ExchangeType.BETFAIR:
+            self.add_order_stream(client)
 
     """ market data """
 
diff --git a/flumine/worker.py b/flumine/worker.py
index 2531062..2e3e893 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))
+        flumine.log_control(events.BalanceEvent(client.account_funds))
 
 
 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.handler_queue.put(events.ClearedMarketsEvent(cleared_markets))
         flumine.log_control(events.ClearedMarketsEvent(cleared_markets))
+        flumine.handler_queue.put(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_baseflumine.py b/tests/test_baseflumine.py
index f90b498..4558083 100644
--- a/tests/test_baseflumine.py
+++ b/tests/test_baseflumine.py
@@ -170,9 +170,8 @@ class BaseFlumineTest(unittest.TestCase):
         mock_event.callback.assert_called_with(self.base_flumine, mock_event)
         mock__process_market_orders.assert_called_with(mock_market)
 
-    @mock.patch("flumine.baseflumine.BaseFlumine.info")
     @mock.patch("flumine.baseflumine.BaseFlumine.log_control")
-    def test__process_close_market(self, mock_log_control, mock_info):
+    def test__process_close_market(self, mock_log_control):
         mock_strategy = mock.Mock()
         mock_strategy.stream_ids = [1, 2, 3]
         self.base_flumine.strategies = [mock_strategy]
@@ -220,9 +219,6 @@ class BaseFlumineTest(unittest.TestCase):
     def test__process_end_flumine(self):
         self.base_flumine._process_end_flumine()
 
-    def test_info(self):
-        self.assertTrue(self.base_flumine.info)
-
     @mock.patch("flumine.baseflumine.events")
     @mock.patch("flumine.baseflumine.BaseFlumine.log_control")
     def test_enter_exit(self, mock_log_control, mock_events):
diff --git a/tests/test_clients.py b/tests/test_clients.py
index c7a1814..aaaa593 100644
--- a/tests/test_clients.py
+++ b/tests/test_clients.py
@@ -27,7 +27,6 @@ class BaseClientTest(unittest.TestCase):
         self.assertEqual(self.base_client.chargeable_transaction_count, 0)
         self.assertIsNone(self.base_client.execution)
         self.assertEqual(self.base_client.trading_controls, [])
-        self.assertTrue(self.base_client.order_stream)
 
     def test_login(self):
         with self.assertRaises(NotImplementedError):
@@ -66,9 +65,6 @@ class BaseClientTest(unittest.TestCase):
         with self.assertRaises(NotImplementedError):
             assert self.base_client.min_bsp_liability
 
-    def test_info(self):
-        self.assertTrue(self.base_client.info)
-
 
 class BetfairClientTest(unittest.TestCase):
     def setUp(self):
diff --git a/tests/test_markets.py b/tests/test_markets.py
index 7e4a37c..2dd7c17 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(self.market.market_book.publish_time)
+        mock_order.place.assert_called_with()
         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(self.market.market_book.publish_time)
+        mock_order.place.assert_called_with()
         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 8594152..eafa766 100644
--- a/tests/test_order.py
+++ b/tests/test_order.py
@@ -30,7 +30,6 @@ 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)
@@ -94,7 +93,7 @@ class BaseOrderTest(unittest.TestCase):
 
     def test_place(self):
         with self.assertRaises(NotImplementedError):
-            self.order.place(123)
+            self.order.place()
 
     def test_cancel(self):
         with self.assertRaises(NotImplementedError):
@@ -218,9 +217,8 @@ class BetfairOrderTest(unittest.TestCase):
 
     @mock.patch("flumine.order.order.BetfairOrder.placing")
     def test_place(self, mock_placing):
-        self.order.place(123)
+        self.order.place()
         mock_placing.assert_called_with()
-        self.assertEqual(self.order.publish_time, 123)
 
     @mock.patch(
         "flumine.order.order.BetfairOrder.size_remaining",
diff --git a/tests/test_streams.py b/tests/test_streams.py
index 6bd467c..3da6bd7 100644
--- a/tests/test_streams.py
+++ b/tests/test_streams.py
@@ -58,19 +58,19 @@ class StreamsTest(unittest.TestCase):
         self.streams(mock_strategy)
         self.assertEqual(len(mock_strategy.streams), 0)
 
-    @mock.patch("flumine.streams.streams.Streams.add_order_stream")
-    def test_add_client_betfair(self, mock_add_order_stream):
-        mock_client = mock.Mock(order_stream=True)
-        mock_client.EXCHANGE = streams.ExchangeType.BETFAIR
+    @mock.patch("flumine.streams.streams.Streams.add_simulated_order_stream")
+    def test_add_client_simulated(self, mock_add_simulated_order_stream):
+        mock_client = mock.Mock()
+        mock_client.EXCHANGE = streams.ExchangeType.SIMULATED
         self.streams.add_client(mock_client)
-        mock_add_order_stream.assert_called_with(mock_client)
+        mock_add_simulated_order_stream.assert_called_with()
 
     @mock.patch("flumine.streams.streams.Streams.add_order_stream")
-    def test_add_client_no_order_stream(self, mock_add_order_stream):
-        mock_client = mock.Mock(order_stream=False)
+    def test_add_client_betfair(self, mock_add_order_stream):
+        mock_client = mock.Mock()
         mock_client.EXCHANGE = streams.ExchangeType.BETFAIR
         self.streams.add_client(mock_client)
-        mock_add_order_stream.assert_not_called()
+        mock_add_order_stream.assert_called_with(mock_client)
 
     @mock.patch("flumine.streams.streams.Streams._increment_stream_id")
     def test_add_stream_new(self, mock_increment):