diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-07-31 00:36:05 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-07-31 00:36:05 +0200 |
commit | 51bc7cdec15d093272c259e793a9c691775b5194 (patch) | |
tree | ae9a5f321daa052441b06af7ce5231be2dae4900 /tests | |
parent | 84c9fe338676667b15f1c2601ae23ef945b36db7 (diff) | |
download | Trader-51bc7cdec15d093272c259e793a9c691775b5194.tar.gz Trader-51bc7cdec15d093272c259e793a9c691775b5194.tar.zst Trader-51bc7cdec15d093272c259e793a9c691775b5194.zip |
Eat several positions in the order book after some time spent
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_ccxt_wrapper.py | 32 | ||||
-rw-r--r-- | tests/test_portfolio.py | 25 |
2 files changed, 57 insertions, 0 deletions
diff --git a/tests/test_ccxt_wrapper.py b/tests/test_ccxt_wrapper.py index c326f0a..44e660e 100644 --- a/tests/test_ccxt_wrapper.py +++ b/tests/test_ccxt_wrapper.py | |||
@@ -549,3 +549,35 @@ class poloniexETest(unittest.TestCase): | |||
549 | self.assertTrue(self.s.is_dust_trade(D("0.0000009"), D("1000"))) | 549 | self.assertTrue(self.s.is_dust_trade(D("0.0000009"), D("1000"))) |
550 | self.assertTrue(self.s.is_dust_trade(D("0.000001"), D("10"))) | 550 | self.assertTrue(self.s.is_dust_trade(D("0.000001"), D("10"))) |
551 | self.assertFalse(self.s.is_dust_trade(D("0.000001"), D("100"))) | 551 | self.assertFalse(self.s.is_dust_trade(D("0.000001"), D("100"))) |
552 | |||
553 | def test_fetch_nth_order_book(self): | ||
554 | with mock.patch.object(self.s, "fetch_order_book") as t: | ||
555 | t.return_value = { | ||
556 | "asks": [ | ||
557 | [1.269e-05, 781.23105917], | ||
558 | [1.271e-05, 108.83577689], | ||
559 | [1.276e-05, 19162.15732141], | ||
560 | [1.277e-05, 34.13657561], | ||
561 | [1.28e-05, 95.14285714], | ||
562 | [1.281e-05, 11.13909862], | ||
563 | [1.282e-05, 43.42379871], | ||
564 | [1.284e-05, 493.67767887], | ||
565 | [1.288e-05, 6179.57843281], | ||
566 | [1.289e-05, 235.16250589] | ||
567 | ], | ||
568 | "bids": [ | ||
569 | [1.266e-05, 3496.42283539], | ||
570 | [1.23e-05, 9.02439024], | ||
571 | [1.229e-05, 3244.25987796], | ||
572 | [1.228e-05, 6692.16061185], | ||
573 | [1.207e-05, 9.19635459], | ||
574 | [1.206e-05, 4711.05943978], | ||
575 | [1.194e-05, 84.67400508], | ||
576 | [1.168e-05, 61.75268779], | ||
577 | [1.165e-05, 9.52789699], | ||
578 | [1.157e-05, 16.4900605] | ||
579 | ] | ||
580 | } | ||
581 | self.assertAlmostEqual(D("0.00001289"), self.s.fetch_nth_order_book("BTC/HUC", "ask", 10), 8) | ||
582 | t.assert_called_once_with("BTC/HUC", limit=10) | ||
583 | self.assertAlmostEqual(D("0.00001157"), self.s.fetch_nth_order_book("BTC/HUC", "bid", 10), 8) | ||
diff --git a/tests/test_portfolio.py b/tests/test_portfolio.py index bc69921..d4e5ab9 100644 --- a/tests/test_portfolio.py +++ b/tests/test_portfolio.py | |||
@@ -26,6 +26,12 @@ class ComputationTest(WebMockTestCase): | |||
26 | portfolio.Computation.compute_value("foo", "bid", compute_value="test") | 26 | portfolio.Computation.compute_value("foo", "bid", compute_value="test") |
27 | compute.assert_called_with("foo", "bid") | 27 | compute.assert_called_with("foo", "bid") |
28 | 28 | ||
29 | def test_eat_several(self): | ||
30 | self.m.ccxt.fetch_nth_order_book.return_value = D("0.00001275") | ||
31 | |||
32 | self.assertEqual(D("0.00001275"), portfolio.Computation.eat_several(self.m)({ "symbol": "BTC/HUC" }, "ask")) | ||
33 | |||
34 | |||
29 | @unittest.skipUnless("unit" in limits, "Unit skipped") | 35 | @unittest.skipUnless("unit" in limits, "Unit skipped") |
30 | class TradeTest(WebMockTestCase): | 36 | class TradeTest(WebMockTestCase): |
31 | 37 | ||
@@ -506,6 +512,25 @@ class TradeTest(WebMockTestCase): | |||
506 | trade.orders = [] | 512 | trade.orders = [] |
507 | self.m.report.log_order.reset_mock() | 513 | self.m.report.log_order.reset_mock() |
508 | 514 | ||
515 | with self.subTest(tick=22): | ||
516 | trade.update_order(order_mock, 22) | ||
517 | order_mock.cancel.assert_called() | ||
518 | new_order_mock.run.assert_called() | ||
519 | prepare_order.assert_called_with(compute_value=mock.ANY) | ||
520 | self.m.report.log_order.assert_called() | ||
521 | self.assertEqual(2, self.m.report.log_order.call_count) | ||
522 | calls = [ | ||
523 | mock.call(order_mock, 22, update="market_adjust_eat", | ||
524 | compute_value=mock.ANY, | ||
525 | new_order=new_order_mock), | ||
526 | mock.call(order_mock, 22, new_order=new_order_mock), | ||
527 | ] | ||
528 | self.m.report.log_order.assert_has_calls(calls) | ||
529 | |||
530 | order_mock.reset_mock() | ||
531 | new_order_mock.reset_mock() | ||
532 | trade.orders = [] | ||
533 | self.m.report.log_order.reset_mock() | ||
509 | 534 | ||
510 | def test_print_with_order(self): | 535 | def test_print_with_order(self): |
511 | value_from = portfolio.Amount("BTC", "0.5") | 536 | value_from = portfolio.Amount("BTC", "0.5") |