diff options
Diffstat (limited to 'test.py')
-rw-r--r-- | test.py | 73 |
1 files changed, 54 insertions, 19 deletions
@@ -653,6 +653,8 @@ class HelperTest(WebMockTestCase): | |||
653 | "total": D("10000.0") | 653 | "total": D("10000.0") |
654 | }, | 654 | }, |
655 | } | 655 | } |
656 | portfolio.BalanceStore.fetch_balances(market, tag="tag") | ||
657 | |||
656 | helper.prepare_trades(market) | 658 | helper.prepare_trades(market) |
657 | compute_trades.assert_called() | 659 | compute_trades.assert_called() |
658 | 660 | ||
@@ -663,7 +665,7 @@ class HelperTest(WebMockTestCase): | |||
663 | self.assertEqual(D("0.2525"), call[0][1]["BTC"].value) | 665 | self.assertEqual(D("0.2525"), call[0][1]["BTC"].value) |
664 | self.assertEqual(D("0.7575"), call[0][1]["XEM"].value) | 666 | self.assertEqual(D("0.7575"), call[0][1]["XEM"].value) |
665 | report_store_h.log_stage.assert_called_once_with("prepare_trades") | 667 | report_store_h.log_stage.assert_called_once_with("prepare_trades") |
666 | report_store.log_balances.assert_called_once_with(market) | 668 | report_store.log_balances.assert_called_once_with(market, tag="tag") |
667 | 669 | ||
668 | @mock.patch.object(portfolio.Portfolio, "repartition") | 670 | @mock.patch.object(portfolio.Portfolio, "repartition") |
669 | @mock.patch.object(helper, "get_ticker") | 671 | @mock.patch.object(helper, "get_ticker") |
@@ -700,6 +702,8 @@ class HelperTest(WebMockTestCase): | |||
700 | "total": D("10000.0") | 702 | "total": D("10000.0") |
701 | }, | 703 | }, |
702 | } | 704 | } |
705 | portfolio.BalanceStore.fetch_balances(market, tag="tag") | ||
706 | |||
703 | helper.update_trades(market) | 707 | helper.update_trades(market) |
704 | compute_trades.assert_called() | 708 | compute_trades.assert_called() |
705 | 709 | ||
@@ -710,7 +714,7 @@ class HelperTest(WebMockTestCase): | |||
710 | self.assertEqual(D("0.2525"), call[0][1]["BTC"].value) | 714 | self.assertEqual(D("0.2525"), call[0][1]["BTC"].value) |
711 | self.assertEqual(D("0.7575"), call[0][1]["XEM"].value) | 715 | self.assertEqual(D("0.7575"), call[0][1]["XEM"].value) |
712 | report_store_h.log_stage.assert_called_once_with("update_trades") | 716 | report_store_h.log_stage.assert_called_once_with("update_trades") |
713 | report_store.log_balances.assert_called_once_with(market) | 717 | report_store.log_balances.assert_called_once_with(market, tag="tag") |
714 | 718 | ||
715 | @mock.patch.object(portfolio.Portfolio, "repartition") | 719 | @mock.patch.object(portfolio.Portfolio, "repartition") |
716 | @mock.patch.object(helper, "get_ticker") | 720 | @mock.patch.object(helper, "get_ticker") |
@@ -741,6 +745,8 @@ class HelperTest(WebMockTestCase): | |||
741 | "total": D("10000.0") | 745 | "total": D("10000.0") |
742 | }, | 746 | }, |
743 | } | 747 | } |
748 | portfolio.BalanceStore.fetch_balances(market, tag="tag") | ||
749 | |||
744 | helper.prepare_trades_to_sell_all(market) | 750 | helper.prepare_trades_to_sell_all(market) |
745 | repartition.assert_not_called() | 751 | repartition.assert_not_called() |
746 | compute_trades.assert_called() | 752 | compute_trades.assert_called() |
@@ -751,7 +757,7 @@ class HelperTest(WebMockTestCase): | |||
751 | self.assertEqual(D("0.01"), call[0][0]["XVG"].value) | 757 | self.assertEqual(D("0.01"), call[0][0]["XVG"].value) |
752 | self.assertEqual(D("1.01"), call[0][1]["BTC"].value) | 758 | self.assertEqual(D("1.01"), call[0][1]["BTC"].value) |
753 | report_store_h.log_stage.assert_called_once_with("prepare_trades_to_sell_all") | 759 | report_store_h.log_stage.assert_called_once_with("prepare_trades_to_sell_all") |
754 | report_store.log_balances.assert_called_once_with(market) | 760 | report_store.log_balances.assert_called_once_with(market, tag="tag") |
755 | 761 | ||
756 | @mock.patch.object(portfolio.time, "sleep") | 762 | @mock.patch.object(portfolio.time, "sleep") |
757 | @mock.patch.object(portfolio.TradeStore, "all_orders") | 763 | @mock.patch.object(portfolio.TradeStore, "all_orders") |
@@ -875,8 +881,9 @@ class HelperTest(WebMockTestCase): | |||
875 | 881 | ||
876 | @mock.patch.object(helper, "prepare_trades") | 882 | @mock.patch.object(helper, "prepare_trades") |
877 | @mock.patch.object(portfolio.TradeStore, "prepare_orders") | 883 | @mock.patch.object(portfolio.TradeStore, "prepare_orders") |
884 | @mock.patch.object(portfolio.BalanceStore, "fetch_balances") | ||
878 | @mock.patch.object(portfolio.ReportStore, "log_stage") | 885 | @mock.patch.object(portfolio.ReportStore, "log_stage") |
879 | def test_print_orders(self, log_stage, prepare_orders, prepare_trades): | 886 | def test_print_orders(self, log_stage, fetch_balances, prepare_orders, prepare_trades): |
880 | market = mock.Mock() | 887 | market = mock.Mock() |
881 | portfolio.BalanceStore.all = { | 888 | portfolio.BalanceStore.all = { |
882 | "BTC": portfolio.Balance("BTC", { | 889 | "BTC": portfolio.Balance("BTC", { |
@@ -890,7 +897,9 @@ class HelperTest(WebMockTestCase): | |||
890 | "exchange_free": 3, | 897 | "exchange_free": 3, |
891 | "exchange_used": 0}), | 898 | "exchange_used": 0}), |
892 | } | 899 | } |
900 | |||
893 | helper.print_orders(market) | 901 | helper.print_orders(market) |
902 | fetch_balances.assert_called_with(market, tag="print_orders") | ||
894 | prepare_trades.assert_called_with(market, base_currency="BTC", | 903 | prepare_trades.assert_called_with(market, base_currency="BTC", |
895 | compute_value="average", debug=True) | 904 | compute_value="average", debug=True) |
896 | prepare_orders.assert_called_with(compute_value="average") | 905 | prepare_orders.assert_called_with(compute_value="average") |
@@ -928,9 +937,11 @@ class HelperTest(WebMockTestCase): | |||
928 | @mock.patch.object(helper, "follow_orders") | 937 | @mock.patch.object(helper, "follow_orders") |
929 | @mock.patch.object(portfolio.TradeStore, "prepare_orders") | 938 | @mock.patch.object(portfolio.TradeStore, "prepare_orders") |
930 | @mock.patch.object(portfolio.TradeStore, "run_orders") | 939 | @mock.patch.object(portfolio.TradeStore, "run_orders") |
940 | @mock.patch.object(portfolio.BalanceStore, "fetch_balances") | ||
931 | @mock.patch.object(portfolio.ReportStore, "log_stage") | 941 | @mock.patch.object(portfolio.ReportStore, "log_stage") |
932 | def test_process_sell_needed__1_sell(self, log_stage, run_orders, | 942 | def test_process_sell_needed__1_sell(self, log_stage, |
933 | prepare_orders, follow_orders, prepare_trades): | 943 | fetch_balances, run_orders, prepare_orders, follow_orders, |
944 | prepare_trades): | ||
934 | market = mock.Mock() | 945 | market = mock.Mock() |
935 | portfolio.BalanceStore.all = { | 946 | portfolio.BalanceStore.all = { |
936 | "BTC": portfolio.Balance("BTC", { | 947 | "BTC": portfolio.Balance("BTC", { |
@@ -945,6 +956,10 @@ class HelperTest(WebMockTestCase): | |||
945 | "exchange_used": 0}), | 956 | "exchange_used": 0}), |
946 | } | 957 | } |
947 | helper.process_sell_needed__1_sell(market) | 958 | helper.process_sell_needed__1_sell(market) |
959 | fetch_balances.assert_has_calls([ | ||
960 | mock.call(market, tag="process_sell_needed__1_sell_begin"), | ||
961 | mock.call(market, tag="process_sell_needed__1_sell_end"), | ||
962 | ]) | ||
948 | prepare_trades.assert_called_with(market, base_currency="BTC", | 963 | prepare_trades.assert_called_with(market, base_currency="BTC", |
949 | liquidity="medium", debug=False) | 964 | liquidity="medium", debug=False) |
950 | prepare_orders.assert_called_with(compute_value="average", | 965 | prepare_orders.assert_called_with(compute_value="average", |
@@ -958,10 +973,11 @@ class HelperTest(WebMockTestCase): | |||
958 | @mock.patch.object(helper, "move_balances") | 973 | @mock.patch.object(helper, "move_balances") |
959 | @mock.patch.object(portfolio.TradeStore, "prepare_orders") | 974 | @mock.patch.object(portfolio.TradeStore, "prepare_orders") |
960 | @mock.patch.object(portfolio.TradeStore, "run_orders") | 975 | @mock.patch.object(portfolio.TradeStore, "run_orders") |
976 | @mock.patch.object(portfolio.BalanceStore, "fetch_balances") | ||
961 | @mock.patch.object(portfolio.ReportStore, "log_stage") | 977 | @mock.patch.object(portfolio.ReportStore, "log_stage") |
962 | def test_process_sell_needed__2_buy(self, log_stage, run_orders, | 978 | def test_process_sell_needed__2_buy(self, log_stage, fetch_balances, |
963 | prepare_orders, move_balances, | 979 | run_orders, prepare_orders, move_balances, follow_orders, |
964 | follow_orders, update_trades): | 980 | update_trades): |
965 | market = mock.Mock() | 981 | market = mock.Mock() |
966 | portfolio.BalanceStore.all = { | 982 | portfolio.BalanceStore.all = { |
967 | "BTC": portfolio.Balance("BTC", { | 983 | "BTC": portfolio.Balance("BTC", { |
@@ -976,6 +992,10 @@ class HelperTest(WebMockTestCase): | |||
976 | "exchange_used": 0}), | 992 | "exchange_used": 0}), |
977 | } | 993 | } |
978 | helper.process_sell_needed__2_buy(market) | 994 | helper.process_sell_needed__2_buy(market) |
995 | fetch_balances.assert_has_calls([ | ||
996 | mock.call(market, tag="process_sell_needed__2_buy_begin"), | ||
997 | mock.call(market, tag="process_sell_needed__2_buy_end"), | ||
998 | ]) | ||
979 | update_trades.assert_called_with(market, base_currency="BTC", | 999 | update_trades.assert_called_with(market, base_currency="BTC", |
980 | debug=False, liquidity="medium", only="acquire") | 1000 | debug=False, liquidity="medium", only="acquire") |
981 | prepare_orders.assert_called_with(compute_value="average", | 1001 | prepare_orders.assert_called_with(compute_value="average", |
@@ -989,9 +1009,11 @@ class HelperTest(WebMockTestCase): | |||
989 | @mock.patch.object(helper, "follow_orders") | 1009 | @mock.patch.object(helper, "follow_orders") |
990 | @mock.patch.object(portfolio.TradeStore, "prepare_orders") | 1010 | @mock.patch.object(portfolio.TradeStore, "prepare_orders") |
991 | @mock.patch.object(portfolio.TradeStore, "run_orders") | 1011 | @mock.patch.object(portfolio.TradeStore, "run_orders") |
1012 | @mock.patch.object(portfolio.BalanceStore, "fetch_balances") | ||
992 | @mock.patch.object(portfolio.ReportStore, "log_stage") | 1013 | @mock.patch.object(portfolio.ReportStore, "log_stage") |
993 | def test_process_sell_all__1_sell(self, log_stage, run_orders, | 1014 | def test_process_sell_all__1_sell(self, log_stage, fetch_balances, |
994 | prepare_orders, follow_orders, prepare_trades_to_sell_all): | 1015 | run_orders, prepare_orders, follow_orders, |
1016 | prepare_trades_to_sell_all): | ||
995 | market = mock.Mock() | 1017 | market = mock.Mock() |
996 | portfolio.BalanceStore.all = { | 1018 | portfolio.BalanceStore.all = { |
997 | "BTC": portfolio.Balance("BTC", { | 1019 | "BTC": portfolio.Balance("BTC", { |
@@ -1006,6 +1028,10 @@ class HelperTest(WebMockTestCase): | |||
1006 | "exchange_used": 0}), | 1028 | "exchange_used": 0}), |
1007 | } | 1029 | } |
1008 | helper.process_sell_all__1_all_sell(market) | 1030 | helper.process_sell_all__1_all_sell(market) |
1031 | fetch_balances.assert_has_calls([ | ||
1032 | mock.call(market, tag="process_sell_all__1_all_sell_begin"), | ||
1033 | mock.call(market, tag="process_sell_all__1_all_sell_end"), | ||
1034 | ]) | ||
1009 | prepare_trades_to_sell_all.assert_called_with(market, base_currency="BTC", | 1035 | prepare_trades_to_sell_all.assert_called_with(market, base_currency="BTC", |
1010 | debug=False) | 1036 | debug=False) |
1011 | prepare_orders.assert_called_with(compute_value="average") | 1037 | prepare_orders.assert_called_with(compute_value="average") |
@@ -1018,10 +1044,11 @@ class HelperTest(WebMockTestCase): | |||
1018 | @mock.patch.object(helper, "move_balances") | 1044 | @mock.patch.object(helper, "move_balances") |
1019 | @mock.patch.object(portfolio.TradeStore, "prepare_orders") | 1045 | @mock.patch.object(portfolio.TradeStore, "prepare_orders") |
1020 | @mock.patch.object(portfolio.TradeStore, "run_orders") | 1046 | @mock.patch.object(portfolio.TradeStore, "run_orders") |
1047 | @mock.patch.object(portfolio.BalanceStore, "fetch_balances") | ||
1021 | @mock.patch.object(portfolio.ReportStore, "log_stage") | 1048 | @mock.patch.object(portfolio.ReportStore, "log_stage") |
1022 | def test_process_sell_all__2_all_buy(self, log_stage, run_orders, | 1049 | def test_process_sell_all__2_all_buy(self, log_stage, |
1023 | prepare_orders, move_balances, follow_orders, | 1050 | fetch_balances, run_orders, prepare_orders, move_balances, |
1024 | prepare_trades): | 1051 | follow_orders, prepare_trades): |
1025 | market = mock.Mock() | 1052 | market = mock.Mock() |
1026 | portfolio.BalanceStore.all = { | 1053 | portfolio.BalanceStore.all = { |
1027 | "BTC": portfolio.Balance("BTC", { | 1054 | "BTC": portfolio.Balance("BTC", { |
@@ -1036,6 +1063,10 @@ class HelperTest(WebMockTestCase): | |||
1036 | "exchange_used": 0}), | 1063 | "exchange_used": 0}), |
1037 | } | 1064 | } |
1038 | helper.process_sell_all__2_all_buy(market) | 1065 | helper.process_sell_all__2_all_buy(market) |
1066 | fetch_balances.assert_has_calls([ | ||
1067 | mock.call(market, tag="process_sell_all__2_all_buy_begin"), | ||
1068 | mock.call(market, tag="process_sell_all__2_all_buy_end"), | ||
1069 | ]) | ||
1039 | prepare_trades.assert_called_with(market, base_currency="BTC", | 1070 | prepare_trades.assert_called_with(market, base_currency="BTC", |
1040 | liquidity="medium", debug=False) | 1071 | liquidity="medium", debug=False) |
1041 | prepare_orders.assert_called_with(compute_value="average") | 1072 | prepare_orders.assert_called_with(compute_value="average") |
@@ -1308,10 +1339,10 @@ class BalanceStoreTest(WebMockTestCase): | |||
1308 | portfolio.BalanceStore.all["ETC"] = portfolio.Balance("ETC", { | 1339 | portfolio.BalanceStore.all["ETC"] = portfolio.Balance("ETC", { |
1309 | "exchange_total": "1", "exchange_free": "0", | 1340 | "exchange_total": "1", "exchange_free": "0", |
1310 | "exchange_used": "1" }) | 1341 | "exchange_used": "1" }) |
1311 | portfolio.BalanceStore.fetch_balances(market) | 1342 | portfolio.BalanceStore.fetch_balances(market, tag="foo") |
1312 | self.assertEqual(0, portfolio.BalanceStore.all["ETC"].total) | 1343 | self.assertEqual(0, portfolio.BalanceStore.all["ETC"].total) |
1313 | self.assertListEqual(["USDT", "XVG", "XMR", "ETC"], list(portfolio.BalanceStore.currencies())) | 1344 | self.assertListEqual(["USDT", "XVG", "XMR", "ETC"], list(portfolio.BalanceStore.currencies())) |
1314 | log_balances.assert_called_with(market) | 1345 | log_balances.assert_called_with(market, tag="foo") |
1315 | 1346 | ||
1316 | @mock.patch.object(portfolio.Portfolio, "repartition") | 1347 | @mock.patch.object(portfolio.Portfolio, "repartition") |
1317 | @mock.patch.object(portfolio.ReportStore, "log_balances") | 1348 | @mock.patch.object(portfolio.ReportStore, "log_balances") |
@@ -1336,7 +1367,7 @@ class BalanceStoreTest(WebMockTestCase): | |||
1336 | self.assertEqual(D("2.6"), amounts["BTC"].value) | 1367 | self.assertEqual(D("2.6"), amounts["BTC"].value) |
1337 | self.assertEqual(D("7.5"), amounts["XEM"].value) | 1368 | self.assertEqual(D("7.5"), amounts["XEM"].value) |
1338 | self.assertEqual(D("-1.0"), amounts["DASH"].value) | 1369 | self.assertEqual(D("-1.0"), amounts["DASH"].value) |
1339 | log_balances.assert_called_with(market) | 1370 | log_balances.assert_called_with(market, tag=None) |
1340 | log_dispatch.assert_called_once_with(portfolio.Amount("BTC", | 1371 | log_dispatch.assert_called_once_with(portfolio.Amount("BTC", |
1341 | "11.1"), amounts, "medium", repartition_hash) | 1372 | "11.1"), amounts, "medium", repartition_hash) |
1342 | 1373 | ||
@@ -2317,13 +2348,17 @@ class ReportStoreTest(WebMockTestCase): | |||
2317 | balance_store.as_json.return_value = "json" | 2348 | balance_store.as_json.return_value = "json" |
2318 | balance_store.all = { "FOO": "bar", "BAR": "baz" } | 2349 | balance_store.all = { "FOO": "bar", "BAR": "baz" } |
2319 | 2350 | ||
2320 | portfolio.ReportStore.log_balances("market") | 2351 | portfolio.ReportStore.log_balances("market", tag="tag") |
2321 | print_log.assert_has_calls([ | 2352 | print_log.assert_has_calls([ |
2322 | mock.call("[Balance]"), | 2353 | mock.call("[Balance]"), |
2323 | mock.call("\tbar"), | 2354 | mock.call("\tbar"), |
2324 | mock.call("\tbaz"), | 2355 | mock.call("\tbaz"), |
2325 | ]) | 2356 | ]) |
2326 | add_log.assert_called_once_with({'type': 'balance', 'balances': 'json'}) | 2357 | add_log.assert_called_once_with({ |
2358 | 'type': 'balance', | ||
2359 | 'balances': 'json', | ||
2360 | 'tag': 'tag' | ||
2361 | }) | ||
2327 | 2362 | ||
2328 | @mock.patch.object(portfolio.ReportStore, "print_log") | 2363 | @mock.patch.object(portfolio.ReportStore, "print_log") |
2329 | @mock.patch.object(portfolio.ReportStore, "add_log") | 2364 | @mock.patch.object(portfolio.ReportStore, "add_log") |