diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-03-01 17:39:48 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2018-03-01 17:39:48 +0100 |
commit | 065ee3422a6ee9d40136cfa6b272e951e15c2e50 (patch) | |
tree | b93618243649704ddf6a8d16e6adee3f3650f7bc | |
parent | 23f4616a85bef7e9acc57740f889a2a0346788af (diff) | |
download | Trader-065ee3422a6ee9d40136cfa6b272e951e15c2e50.tar.gz Trader-065ee3422a6ee9d40136cfa6b272e951e15c2e50.tar.zst Trader-065ee3422a6ee9d40136cfa6b272e951e15c2e50.zip |
Add processors
-rw-r--r-- | helper.py | 19 | ||||
-rw-r--r-- | test.py | 28 |
2 files changed, 31 insertions, 16 deletions
@@ -129,8 +129,8 @@ def main_process_market(user_market, actions, before=False, after=False): | |||
129 | if before: | 129 | if before: |
130 | process_sell_all__1_all_sell(user_market) | 130 | process_sell_all__1_all_sell(user_market) |
131 | if after: | 131 | if after: |
132 | portfolio.Portfolio.wait_for_recent(user_market) | 132 | process_sell_all__2_wait(user_market) |
133 | process_sell_all__2_all_buy(user_market) | 133 | process_sell_all__3_all_buy(user_market) |
134 | else: | 134 | else: |
135 | for action in actions: | 135 | for action in actions: |
136 | if action in globals(): | 136 | if action in globals(): |
@@ -191,15 +191,20 @@ def process_sell_all__1_all_sell(market, base_currency="BTC", liquidity="medium" | |||
191 | market.balances.fetch_balances(tag="process_sell_all__1_all_sell_end") | 191 | market.balances.fetch_balances(tag="process_sell_all__1_all_sell_end") |
192 | market.report.log_stage("process_sell_all__1_all_sell_end") | 192 | market.report.log_stage("process_sell_all__1_all_sell_end") |
193 | 193 | ||
194 | def process_sell_all__2_all_buy(market, base_currency="BTC", liquidity="medium"): | 194 | def process_sell_all__2_wait(market, liquidity="medium", base_currency="BTC"): |
195 | market.report.log_stage("process_sell_all__2_all_buy_begin") | 195 | market.report.log_stage("process_sell_all__2_wait_begin") |
196 | market.balances.fetch_balances(tag="process_sell_all__2_all_buy_begin") | 196 | portfolio.Portfolio.wait_for_recent(market) |
197 | market.report.log_stage("process_sell_all__2_wait_end") | ||
198 | |||
199 | def process_sell_all__3_all_buy(market, base_currency="BTC", liquidity="medium"): | ||
200 | market.report.log_stage("process_sell_all__3_all_buy_begin") | ||
201 | market.balances.fetch_balances(tag="process_sell_all__3_all_buy_begin") | ||
197 | market.prepare_trades(liquidity=liquidity, base_currency=base_currency) | 202 | market.prepare_trades(liquidity=liquidity, base_currency=base_currency) |
198 | market.trades.prepare_orders(compute_value="average") | 203 | market.trades.prepare_orders(compute_value="average") |
199 | market.move_balances() | 204 | market.move_balances() |
200 | market.trades.run_orders() | 205 | market.trades.run_orders() |
201 | market.follow_orders() | 206 | market.follow_orders() |
202 | market.balances.fetch_balances(tag="process_sell_all__2_all_buy_end") | 207 | market.balances.fetch_balances(tag="process_sell_all__3_all_buy_end") |
203 | market.report.log_stage("process_sell_all__2_all_buy_end") | 208 | market.report.log_stage("process_sell_all__3_all_buy_end") |
204 | 209 | ||
205 | 210 | ||
@@ -2875,9 +2875,9 @@ class HelperTest(WebMockTestCase): | |||
2875 | self.assertRegex(stdout_mock.getvalue(), "impossible to store report file: FileNotFoundError;") | 2875 | self.assertRegex(stdout_mock.getvalue(), "impossible to store report file: FileNotFoundError;") |
2876 | 2876 | ||
2877 | @mock.patch("helper.process_sell_all__1_all_sell") | 2877 | @mock.patch("helper.process_sell_all__1_all_sell") |
2878 | @mock.patch("helper.process_sell_all__2_all_buy") | 2878 | @mock.patch("helper.process_sell_all__2_wait") |
2879 | @mock.patch("portfolio.Portfolio.wait_for_recent") | 2879 | @mock.patch("helper.process_sell_all__3_all_buy") |
2880 | def test_main_process_market(self, wait, buy, sell): | 2880 | def test_main_process_market(self, buy, wait, sell): |
2881 | with self.subTest(before=False, after=False): | 2881 | with self.subTest(before=False, after=False): |
2882 | helper.main_process_market("user", None) | 2882 | helper.main_process_market("user", None) |
2883 | 2883 | ||
@@ -3117,12 +3117,22 @@ class HelperTest(WebMockTestCase): | |||
3117 | mock.call("process_sell_all__1_all_sell_end") | 3117 | mock.call("process_sell_all__1_all_sell_end") |
3118 | ]) | 3118 | ]) |
3119 | 3119 | ||
3120 | def test_process_sell_all__2_all_buy(self): | 3120 | @mock.patch("portfolio.Portfolio.wait_for_recent") |
3121 | helper.process_sell_all__2_all_buy(self.m) | 3121 | def test_process_sell_all__2_wait(self, wait): |
3122 | helper.process_sell_all__2_wait(self.m) | ||
3123 | |||
3124 | wait.assert_called_once_with(self.m) | ||
3125 | self.m.report.log_stage.assert_has_calls([ | ||
3126 | mock.call("process_sell_all__2_wait_begin"), | ||
3127 | mock.call("process_sell_all__2_wait_end") | ||
3128 | ]) | ||
3129 | |||
3130 | def test_process_sell_all__3_all_buy(self): | ||
3131 | helper.process_sell_all__3_all_buy(self.m) | ||
3122 | 3132 | ||
3123 | self.m.balances.fetch_balances.assert_has_calls([ | 3133 | self.m.balances.fetch_balances.assert_has_calls([ |
3124 | mock.call(tag="process_sell_all__2_all_buy_begin"), | 3134 | mock.call(tag="process_sell_all__3_all_buy_begin"), |
3125 | mock.call(tag="process_sell_all__2_all_buy_end"), | 3135 | mock.call(tag="process_sell_all__3_all_buy_end"), |
3126 | ]) | 3136 | ]) |
3127 | self.m.prepare_trades.assert_called_with(base_currency="BTC", | 3137 | self.m.prepare_trades.assert_called_with(base_currency="BTC", |
3128 | liquidity="medium") | 3138 | liquidity="medium") |
@@ -3131,8 +3141,8 @@ class HelperTest(WebMockTestCase): | |||
3131 | self.m.trades.run_orders.assert_called() | 3141 | self.m.trades.run_orders.assert_called() |
3132 | self.m.follow_orders.assert_called() | 3142 | self.m.follow_orders.assert_called() |
3133 | self.m.report.log_stage.assert_has_calls([ | 3143 | self.m.report.log_stage.assert_has_calls([ |
3134 | mock.call("process_sell_all__2_all_buy_begin"), | 3144 | mock.call("process_sell_all__3_all_buy_begin"), |
3135 | mock.call("process_sell_all__2_all_buy_end") | 3145 | mock.call("process_sell_all__3_all_buy_end") |
3136 | ]) | 3146 | ]) |
3137 | 3147 | ||
3138 | @unittest.skipUnless("acceptance" in limits, "Acceptance skipped") | 3148 | @unittest.skipUnless("acceptance" in limits, "Acceptance skipped") |