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")
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]: