]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Trader.git/commitdiff
Fix orders disappearing but finally not
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 30 Jul 2018 21:18:00 +0000 (23:18 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Mon, 30 Jul 2018 21:18:00 +0000 (23:18 +0200)
market.py
tests/test_market.py

index d7b05ce7abb64486a2aad30be1a2317d763ce287..41c4c9c5652d6c24629aca26d21e58797a7eb6e5 100644 (file)
--- a/market.py
+++ b/market.py
@@ -206,8 +206,9 @@ class Market:
                             message="{} disappeared, recreating it".format(order))
                     new_order = order.trade.prepare_order(
                             compute_value=order.trade.tick_actions_recreate(tick))
-                    new_order.run()
-                    self.report.log_order(order, tick, new_order=new_order)
+                    if new_order is not None:
+                        new_order.run()
+                        self.report.log_order(order, tick, new_order=new_order)
 
         self.report.log_stage("follow_orders_end")
 
index 07188aca1d7c7344d315d0501f1740fe0ed4511b..c02968672aa46cdadb64379ac40d87e970c1e7ea 100644 (file)
@@ -402,6 +402,40 @@ class MarketTest(WebMockTestCase):
             m.report.log_order.assert_called_with(order_mock2, 2, new_order=new_order_mock)
             new_order_mock.run.assert_called_once_with()
 
+        with self.subTest("disappearing order no action to do"), \
+                mock.patch("market.ReportStore"):
+            all_orders.reset_mock()
+            m = market.Market(self.ccxt, self.market_args())
+
+            order_mock1 = mock.Mock()
+            order_mock2 = mock.Mock()
+            all_orders.side_effect = [
+                    [order_mock1, order_mock2],
+                    [order_mock1, order_mock2],
+
+                    [order_mock1, order_mock2],
+                    [order_mock1, order_mock2],
+
+                    []
+                    ]
+
+            order_mock1.get_status.side_effect = ["open", "closed"]
+            order_mock2.get_status.side_effect = ["open", "error_disappeared"]
+
+            order_mock1.trade = mock.Mock()
+            trade_mock = mock.Mock()
+            order_mock2.trade = trade_mock
+
+            trade_mock.tick_actions_recreate.return_value = "tick1"
+            trade_mock.prepare_order.return_value = None
+
+            m.follow_orders()
+
+            trade_mock.tick_actions_recreate.assert_called_once_with(2)
+            trade_mock.prepare_order.assert_called_once_with(compute_value="tick1")
+            m.report.log_error.assert_called_once_with("follow_orders", message=mock.ANY)
+            m.report.log_order.assert_called_with(order_mock2, 2, finished=True)
+
     @mock.patch.object(market.BalanceStore, "fetch_balances")
     def test_move_balance(self, fetch_balances):
         for debug in [True, False]: