diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-07-30 23:18:00 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-07-30 23:18:00 +0200 |
commit | 84c9fe338676667b15f1c2601ae23ef945b36db7 (patch) | |
tree | efea9e0741e0253217c57a131e9b3ad76dfdf91f | |
parent | 4b598ca6f91236c94da250282ac8c89c7d947ee2 (diff) | |
download | Trader-84c9fe338676667b15f1c2601ae23ef945b36db7.tar.gz Trader-84c9fe338676667b15f1c2601ae23ef945b36db7.tar.zst Trader-84c9fe338676667b15f1c2601ae23ef945b36db7.zip |
Fix orders disappearing but finally not
-rw-r--r-- | market.py | 5 | ||||
-rw-r--r-- | tests/test_market.py | 34 |
2 files changed, 37 insertions, 2 deletions
@@ -206,8 +206,9 @@ class Market: | |||
206 | message="{} disappeared, recreating it".format(order)) | 206 | message="{} disappeared, recreating it".format(order)) |
207 | new_order = order.trade.prepare_order( | 207 | new_order = order.trade.prepare_order( |
208 | compute_value=order.trade.tick_actions_recreate(tick)) | 208 | compute_value=order.trade.tick_actions_recreate(tick)) |
209 | new_order.run() | 209 | if new_order is not None: |
210 | self.report.log_order(order, tick, new_order=new_order) | 210 | new_order.run() |
211 | self.report.log_order(order, tick, new_order=new_order) | ||
211 | 212 | ||
212 | self.report.log_stage("follow_orders_end") | 213 | self.report.log_stage("follow_orders_end") |
213 | 214 | ||
diff --git a/tests/test_market.py b/tests/test_market.py index 07188ac..c029686 100644 --- a/tests/test_market.py +++ b/tests/test_market.py | |||
@@ -402,6 +402,40 @@ class MarketTest(WebMockTestCase): | |||
402 | m.report.log_order.assert_called_with(order_mock2, 2, new_order=new_order_mock) | 402 | m.report.log_order.assert_called_with(order_mock2, 2, new_order=new_order_mock) |
403 | new_order_mock.run.assert_called_once_with() | 403 | new_order_mock.run.assert_called_once_with() |
404 | 404 | ||
405 | with self.subTest("disappearing order no action to do"), \ | ||
406 | mock.patch("market.ReportStore"): | ||
407 | all_orders.reset_mock() | ||
408 | m = market.Market(self.ccxt, self.market_args()) | ||
409 | |||
410 | order_mock1 = mock.Mock() | ||
411 | order_mock2 = mock.Mock() | ||
412 | all_orders.side_effect = [ | ||
413 | [order_mock1, order_mock2], | ||
414 | [order_mock1, order_mock2], | ||
415 | |||
416 | [order_mock1, order_mock2], | ||
417 | [order_mock1, order_mock2], | ||
418 | |||
419 | [] | ||
420 | ] | ||
421 | |||
422 | order_mock1.get_status.side_effect = ["open", "closed"] | ||
423 | order_mock2.get_status.side_effect = ["open", "error_disappeared"] | ||
424 | |||
425 | order_mock1.trade = mock.Mock() | ||
426 | trade_mock = mock.Mock() | ||
427 | order_mock2.trade = trade_mock | ||
428 | |||
429 | trade_mock.tick_actions_recreate.return_value = "tick1" | ||
430 | trade_mock.prepare_order.return_value = None | ||
431 | |||
432 | m.follow_orders() | ||
433 | |||
434 | trade_mock.tick_actions_recreate.assert_called_once_with(2) | ||
435 | trade_mock.prepare_order.assert_called_once_with(compute_value="tick1") | ||
436 | m.report.log_error.assert_called_once_with("follow_orders", message=mock.ANY) | ||
437 | m.report.log_order.assert_called_with(order_mock2, 2, finished=True) | ||
438 | |||
405 | @mock.patch.object(market.BalanceStore, "fetch_balances") | 439 | @mock.patch.object(market.BalanceStore, "fetch_balances") |
406 | def test_move_balance(self, fetch_balances): | 440 | def test_move_balance(self, fetch_balances): |
407 | for debug in [True, False]: | 441 | for debug in [True, False]: |