diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-02-24 22:12:29 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-02-24 22:12:29 +0100 |
commit | 18167a3c502e9d61828067c3f6e56b5182584249 (patch) | |
tree | 9c0fedd7e1e66bf25dfec9515c576d5b9dcdd3f3 | |
parent | 3d0247f944d7510943dfaa64eeb0e15a43b6c989 (diff) | |
download | Trader-18167a3c502e9d61828067c3f6e56b5182584249.tar.gz Trader-18167a3c502e9d61828067c3f6e56b5182584249.tar.zst Trader-18167a3c502e9d61828067c3f6e56b5182584249.zip |
Add tags to balance log
-rw-r--r-- | helper.py | 12 | ||||
-rw-r--r-- | store.py | 7 | ||||
-rw-r--r-- | test.py | 73 |
3 files changed, 67 insertions, 25 deletions
@@ -74,7 +74,6 @@ def fetch_fees(market): | |||
74 | 74 | ||
75 | def prepare_trades(market, base_currency="BTC", liquidity="medium", compute_value="average", debug=False): | 75 | def prepare_trades(market, base_currency="BTC", liquidity="medium", compute_value="average", debug=False): |
76 | ReportStore.log_stage("prepare_trades") | 76 | ReportStore.log_stage("prepare_trades") |
77 | BalanceStore.fetch_balances(market) | ||
78 | values_in_base = BalanceStore.in_currency(base_currency, market, compute_value=compute_value) | 77 | values_in_base = BalanceStore.in_currency(base_currency, market, compute_value=compute_value) |
79 | total_base_value = sum(values_in_base.values()) | 78 | total_base_value = sum(values_in_base.values()) |
80 | new_repartition = BalanceStore.dispatch_assets(total_base_value, liquidity=liquidity) | 79 | new_repartition = BalanceStore.dispatch_assets(total_base_value, liquidity=liquidity) |
@@ -84,7 +83,6 @@ def prepare_trades(market, base_currency="BTC", liquidity="medium", compute_valu | |||
84 | 83 | ||
85 | def update_trades(market, base_currency="BTC", liquidity="medium", compute_value="average", only=None, debug=False): | 84 | def update_trades(market, base_currency="BTC", liquidity="medium", compute_value="average", only=None, debug=False): |
86 | ReportStore.log_stage("update_trades") | 85 | ReportStore.log_stage("update_trades") |
87 | BalanceStore.fetch_balances(market) | ||
88 | values_in_base = BalanceStore.in_currency(base_currency, market, compute_value=compute_value) | 86 | values_in_base = BalanceStore.in_currency(base_currency, market, compute_value=compute_value) |
89 | total_base_value = sum(values_in_base.values()) | 87 | total_base_value = sum(values_in_base.values()) |
90 | new_repartition = BalanceStore.dispatch_assets(total_base_value, liquidity=liquidity) | 88 | new_repartition = BalanceStore.dispatch_assets(total_base_value, liquidity=liquidity) |
@@ -92,7 +90,6 @@ def update_trades(market, base_currency="BTC", liquidity="medium", compute_value | |||
92 | 90 | ||
93 | def prepare_trades_to_sell_all(market, base_currency="BTC", compute_value="average", debug=False): | 91 | def prepare_trades_to_sell_all(market, base_currency="BTC", compute_value="average", debug=False): |
94 | ReportStore.log_stage("prepare_trades_to_sell_all") | 92 | ReportStore.log_stage("prepare_trades_to_sell_all") |
95 | BalanceStore.fetch_balances(market) | ||
96 | values_in_base = BalanceStore.in_currency(base_currency, market, compute_value=compute_value) | 93 | values_in_base = BalanceStore.in_currency(base_currency, market, compute_value=compute_value) |
97 | total_base_value = sum(values_in_base.values()) | 94 | total_base_value = sum(values_in_base.values()) |
98 | new_repartition = BalanceStore.dispatch_assets(total_base_value, repartition={ base_currency: (1, "long") }) | 95 | new_repartition = BalanceStore.dispatch_assets(total_base_value, repartition={ base_currency: (1, "long") }) |
@@ -120,6 +117,7 @@ def follow_orders(sleep=None): | |||
120 | 117 | ||
121 | def print_orders(market, base_currency="BTC"): | 118 | def print_orders(market, base_currency="BTC"): |
122 | ReportStore.log_stage("print_orders") | 119 | ReportStore.log_stage("print_orders") |
120 | BalanceStore.fetch_balances(market, tag="print_orders") | ||
123 | prepare_trades(market, base_currency=base_currency, compute_value="average", debug=True) | 121 | prepare_trades(market, base_currency=base_currency, compute_value="average", debug=True) |
124 | TradeStore.prepare_orders(compute_value="average") | 122 | TradeStore.prepare_orders(compute_value="average") |
125 | 123 | ||
@@ -131,36 +129,44 @@ def print_balances(market, base_currency="BTC"): | |||
131 | 129 | ||
132 | def process_sell_needed__1_sell(market, liquidity="medium", base_currency="BTC", debug=False): | 130 | def process_sell_needed__1_sell(market, liquidity="medium", base_currency="BTC", debug=False): |
133 | ReportStore.log_stage("process_sell_needed__1_sell_begin") | 131 | ReportStore.log_stage("process_sell_needed__1_sell_begin") |
132 | BalanceStore.fetch_balances(market, tag="process_sell_needed__1_sell_begin") | ||
134 | prepare_trades(market, liquidity=liquidity, base_currency=base_currency, debug=debug) | 133 | prepare_trades(market, liquidity=liquidity, base_currency=base_currency, debug=debug) |
135 | TradeStore.prepare_orders(compute_value="average", only="dispose") | 134 | TradeStore.prepare_orders(compute_value="average", only="dispose") |
136 | TradeStore.run_orders() | 135 | TradeStore.run_orders() |
137 | follow_orders() | 136 | follow_orders() |
137 | BalanceStore.fetch_balances(market, tag="process_sell_needed__1_sell_end") | ||
138 | ReportStore.log_stage("process_sell_needed__1_sell_end") | 138 | ReportStore.log_stage("process_sell_needed__1_sell_end") |
139 | 139 | ||
140 | def process_sell_needed__2_buy(market, liquidity="medium", base_currency="BTC", debug=False): | 140 | def process_sell_needed__2_buy(market, liquidity="medium", base_currency="BTC", debug=False): |
141 | ReportStore.log_stage("process_sell_needed__2_buy_begin") | 141 | ReportStore.log_stage("process_sell_needed__2_buy_begin") |
142 | BalanceStore.fetch_balances(market, tag="process_sell_needed__2_buy_begin") | ||
142 | update_trades(market, base_currency=base_currency, liquidity=liquidity, debug=debug, only="acquire") | 143 | update_trades(market, base_currency=base_currency, liquidity=liquidity, debug=debug, only="acquire") |
143 | TradeStore.prepare_orders(compute_value="average", only="acquire") | 144 | TradeStore.prepare_orders(compute_value="average", only="acquire") |
144 | move_balances(market, debug=debug) | 145 | move_balances(market, debug=debug) |
145 | TradeStore.run_orders() | 146 | TradeStore.run_orders() |
146 | follow_orders() | 147 | follow_orders() |
148 | BalanceStore.fetch_balances(market, tag="process_sell_needed__2_buy_end") | ||
147 | ReportStore.log_stage("process_sell_needed__2_buy_end") | 149 | ReportStore.log_stage("process_sell_needed__2_buy_end") |
148 | 150 | ||
149 | def process_sell_all__1_all_sell(market, base_currency="BTC", debug=False, liquidity="medium"): | 151 | def process_sell_all__1_all_sell(market, base_currency="BTC", debug=False, liquidity="medium"): |
150 | ReportStore.log_stage("process_sell_all__1_all_sell_begin") | 152 | ReportStore.log_stage("process_sell_all__1_all_sell_begin") |
153 | BalanceStore.fetch_balances(market, tag="process_sell_all__1_all_sell_begin") | ||
151 | prepare_trades_to_sell_all(market, base_currency=base_currency, debug=debug) | 154 | prepare_trades_to_sell_all(market, base_currency=base_currency, debug=debug) |
152 | TradeStore.prepare_orders(compute_value="average") | 155 | TradeStore.prepare_orders(compute_value="average") |
153 | TradeStore.run_orders() | 156 | TradeStore.run_orders() |
154 | follow_orders() | 157 | follow_orders() |
158 | BalanceStore.fetch_balances(market, tag="process_sell_all__1_all_sell_end") | ||
155 | ReportStore.log_stage("process_sell_all__1_all_sell_end") | 159 | ReportStore.log_stage("process_sell_all__1_all_sell_end") |
156 | 160 | ||
157 | def process_sell_all__2_all_buy(market, base_currency="BTC", debug=False, liquidity="medium"): | 161 | def process_sell_all__2_all_buy(market, base_currency="BTC", debug=False, liquidity="medium"): |
158 | ReportStore.log_stage("process_sell_all__2_all_buy_begin") | 162 | ReportStore.log_stage("process_sell_all__2_all_buy_begin") |
163 | BalanceStore.fetch_balances(market, tag="process_sell_all__2_all_buy_begin") | ||
159 | prepare_trades(market, liquidity=liquidity, base_currency=base_currency, debug=debug) | 164 | prepare_trades(market, liquidity=liquidity, base_currency=base_currency, debug=debug) |
160 | TradeStore.prepare_orders(compute_value="average") | 165 | TradeStore.prepare_orders(compute_value="average") |
161 | move_balances(market, debug=debug) | 166 | move_balances(market, debug=debug) |
162 | TradeStore.run_orders() | 167 | TradeStore.run_orders() |
163 | follow_orders() | 168 | follow_orders() |
169 | BalanceStore.fetch_balances(market, tag="process_sell_all__2_all_buy_end") | ||
164 | ReportStore.log_stage("process_sell_all__2_all_buy_end") | 170 | ReportStore.log_stage("process_sell_all__2_all_buy_end") |
165 | 171 | ||
166 | 172 | ||
@@ -43,13 +43,14 @@ class ReportStore: | |||
43 | }) | 43 | }) |
44 | 44 | ||
45 | @classmethod | 45 | @classmethod |
46 | def log_balances(cls, market): | 46 | def log_balances(cls, market, tag=None): |
47 | cls.print_log("[Balance]") | 47 | cls.print_log("[Balance]") |
48 | for currency, balance in BalanceStore.all.items(): | 48 | for currency, balance in BalanceStore.all.items(): |
49 | cls.print_log("\t{}".format(balance)) | 49 | cls.print_log("\t{}".format(balance)) |
50 | 50 | ||
51 | cls.add_log({ | 51 | cls.add_log({ |
52 | "type": "balance", | 52 | "type": "balance", |
53 | "tag": tag, | ||
53 | "balances": BalanceStore.as_json() | 54 | "balances": BalanceStore.as_json() |
54 | }) | 55 | }) |
55 | 56 | ||
@@ -196,13 +197,13 @@ class BalanceStore: | |||
196 | return amounts | 197 | return amounts |
197 | 198 | ||
198 | @classmethod | 199 | @classmethod |
199 | def fetch_balances(cls, market): | 200 | def fetch_balances(cls, market, tag=None): |
200 | all_balances = market.fetch_all_balances() | 201 | all_balances = market.fetch_all_balances() |
201 | for currency, balance in all_balances.items(): | 202 | for currency, balance in all_balances.items(): |
202 | if balance["exchange_total"] != 0 or balance["margin_total"] != 0 or \ | 203 | if balance["exchange_total"] != 0 or balance["margin_total"] != 0 or \ |
203 | currency in cls.all: | 204 | currency in cls.all: |
204 | cls.all[currency] = portfolio.Balance(currency, balance) | 205 | cls.all[currency] = portfolio.Balance(currency, balance) |
205 | ReportStore.log_balances(market) | 206 | ReportStore.log_balances(market, tag=tag) |
206 | 207 | ||
207 | @classmethod | 208 | @classmethod |
208 | def dispatch_assets(cls, amount, liquidity="medium", repartition=None): | 209 | def dispatch_assets(cls, amount, liquidity="medium", repartition=None): |
@@ -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") |