aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--market.py10
-rw-r--r--store.py4
-rw-r--r--tests/test_market.py34
3 files changed, 26 insertions, 22 deletions
diff --git a/market.py b/market.py
index 546ee94..9612b17 100644
--- a/market.py
+++ b/market.py
@@ -427,16 +427,16 @@ class Processor:
427 self.market.report.log_stage("{}_begin".format(process_name)) 427 self.market.report.log_stage("{}_begin".format(process_name))
428 428
429 if "fetch_balances_begin" in step: 429 if "fetch_balances_begin" in step:
430 self.market.balances.fetch_balances(tag="{}_begin".format(process_name), 430 self.run_action("fetch_balances", step["fetch_balances_begin"],
431 **step["fetch_balances_begin"]) 431 dict(options, tag="{}_begin".format(process_name)))
432 432
433 for action in self.ordered_actions: 433 for action in self.ordered_actions:
434 if action in step: 434 if action in step:
435 self.run_action(action, step[action], options) 435 self.run_action(action, step[action], options)
436 436
437 if "fetch_balances_end" in step: 437 if "fetch_balances_end" in step:
438 self.market.balances.fetch_balances(tag="{}_end".format(process_name), 438 self.run_action("fetch_balances", step["fetch_balances_end"],
439 **step["fetch_balances_end"]) 439 dict(options, tag="{}_end".format(process_name)))
440 440
441 self.market.report.log_stage("{}_end".format(process_name)) 441 self.market.report.log_stage("{}_end".format(process_name))
442 442
@@ -459,6 +459,8 @@ class Processor:
459 method = self.market.trades.close_trades 459 method = self.market.trades.close_trades
460 elif action == "print_tickers": 460 elif action == "print_tickers":
461 method = self.market.print_tickers 461 method = self.market.print_tickers
462 elif action == "fetch_balances":
463 method = self.market.balances.fetch_balances
462 464
463 signature = inspect.getfullargspec(method) 465 signature = inspect.getfullargspec(method)
464 defaults = signature.defaults or [] 466 defaults = signature.defaults or []
diff --git a/store.py b/store.py
index f987bb9..add3df6 100644
--- a/store.py
+++ b/store.py
@@ -304,7 +304,7 @@ class BalanceStore:
304 compute_value, type) 304 compute_value, type)
305 return amounts 305 return amounts
306 306
307 def fetch_balances(self, tag=None, add_portfolio=False, 307 def fetch_balances(self, tag=None, add_portfolio=False, liquidity="medium",
308 checkpoint=None, log_tickers=False, add_usdt=False, 308 checkpoint=None, log_tickers=False, add_usdt=False,
309 ticker_currency="BTC", ticker_compute_value="average", ticker_type="total"): 309 ticker_currency="BTC", ticker_compute_value="average", ticker_type="total"):
310 all_balances = self.market.ccxt.fetch_all_balances() 310 all_balances = self.market.ccxt.fetch_all_balances()
@@ -313,7 +313,7 @@ class BalanceStore:
313 currency in self.all: 313 currency in self.all:
314 self.all[currency] = portfolio.Balance(currency, balance) 314 self.all[currency] = portfolio.Balance(currency, balance)
315 if add_portfolio: 315 if add_portfolio:
316 for currency in Portfolio.repartition(from_cache=True): 316 for currency in Portfolio.repartition(from_cache=True, liquidity=liquidity):
317 self.all.setdefault(currency, portfolio.Balance(currency, {})) 317 self.all.setdefault(currency, portfolio.Balance(currency, {}))
318 if add_usdt: 318 if add_usdt:
319 self.all.setdefault("USDT", portfolio.Balance("USDT", {})) 319 self.all.setdefault("USDT", portfolio.Balance("USDT", {}))
diff --git a/tests/test_market.py b/tests/test_market.py
index e6e6f36..9316480 100644
--- a/tests/test_market.py
+++ b/tests/test_market.py
@@ -1057,6 +1057,9 @@ class ProcessorTest(WebMockTestCase):
1057 method, arguments = processor.method_arguments("print_tickers") 1057 method, arguments = processor.method_arguments("print_tickers")
1058 self.assertEqual(m.print_tickers, method) 1058 self.assertEqual(m.print_tickers, method)
1059 1059
1060 method, arguments = processor.method_arguments("fetch_balances")
1061 self.assertEqual(m.balances.fetch_balances, method)
1062
1060 def test_process_step(self): 1063 def test_process_step(self):
1061 processor = market.Processor(self.m) 1064 processor = market.Processor(self.m)
1062 1065
@@ -1069,19 +1072,17 @@ class ProcessorTest(WebMockTestCase):
1069 mock.call("process_foo__2_sell_begin"), 1072 mock.call("process_foo__2_sell_begin"),
1070 mock.call("process_foo__2_sell_end"), 1073 mock.call("process_foo__2_sell_end"),
1071 ]) 1074 ])
1072 self.m.balances.fetch_balances.assert_has_calls([
1073 mock.call(tag="process_foo__2_sell_begin"),
1074 mock.call(tag="process_foo__2_sell_end"),
1075 ])
1076 1075
1077 self.assertEqual(5, run_action.call_count) 1076 self.assertEqual(7, run_action.call_count)
1078 1077
1079 run_action.assert_has_calls([ 1078 run_action.assert_has_calls([
1079 mock.call('fetch_balances', {}, {'foo': 'bar', 'tag': 'process_foo__2_sell_begin'}),
1080 mock.call('prepare_trades', {}, {'foo': 'bar'}), 1080 mock.call('prepare_trades', {}, {'foo': 'bar'}),
1081 mock.call('prepare_orders', {'only': 'dispose', 'compute_value': 'average'}, {'foo': 'bar'}), 1081 mock.call('prepare_orders', {'only': 'dispose', 'compute_value': 'average'}, {'foo': 'bar'}),
1082 mock.call('run_orders', {}, {'foo': 'bar'}), 1082 mock.call('run_orders', {}, {'foo': 'bar'}),
1083 mock.call('follow_orders', {}, {'foo': 'bar'}), 1083 mock.call('follow_orders', {}, {'foo': 'bar'}),
1084 mock.call('close_trades', {}, {'foo': 'bar'}), 1084 mock.call('close_trades', {}, {'foo': 'bar'}),
1085 mock.call('fetch_balances', {}, {'foo': 'bar', 'tag': 'process_foo__2_sell_end'}),
1085 ]) 1086 ])
1086 1087
1087 self.m.reset_mock() 1088 self.m.reset_mock()
@@ -1094,30 +1095,31 @@ class ProcessorTest(WebMockTestCase):
1094 mock.call("process_foo__0_print_balances_begin"), 1095 mock.call("process_foo__0_print_balances_begin"),
1095 mock.call("process_foo__0_print_balances_end"), 1096 mock.call("process_foo__0_print_balances_end"),
1096 ]) 1097 ])
1097 self.m.balances.fetch_balances.assert_has_calls([
1098 mock.call(add_portfolio=True, checkpoint='end',
1099 log_tickers=True,
1100 add_usdt=True,
1101 tag='process_foo__0_print_balances_begin')
1102 ])
1103 1098
1104 self.assertEqual(0, run_action.call_count) 1099 self.assertEqual(1, run_action.call_count)
1100 run_action.assert_has_calls([
1101 mock.call('fetch_balances',
1102 {'checkpoint': 'end', 'log_tickers': True, 'add_usdt': True, 'add_portfolio': True},
1103 {'foo': 'bar', 'tag': 'process_foo__0_print_balances_begin'}),
1104 ])
1105 1105
1106 self.m.reset_mock() 1106 self.m.reset_mock()
1107 with mock.patch.object(processor, "run_action") as run_action: 1107 with mock.patch.object(processor, "run_action") as run_action:
1108 step = processor.scenarios["sell_needed"][1] 1108 step = processor.scenarios["sell_needed"][1]
1109 1109
1110 processor.process_step("foo", step, {"foo":"bar"}) 1110 processor.process_step("foo", step, {"foo":"bar"})
1111 self.m.balances.fetch_balances.assert_not_called() 1111 self.assertEqual(1, run_action.call_count)
1112 1112
1113 self.m.reset_mock() 1113 self.m.reset_mock()
1114 with mock.patch.object(processor, "run_action") as run_action: 1114 with mock.patch.object(processor, "run_action") as run_action:
1115 step = processor.scenarios["print_balances"][0] 1115 step = processor.scenarios["print_balances"][0]
1116 1116
1117 processor.process_step("foo", step, {"foo":"bar"}) 1117 processor.process_step("foo", step, {"foo":"bar"})
1118 self.m.balances.fetch_balances.assert_called_once_with( 1118 run_action.assert_has_calls([
1119 add_portfolio=True, add_usdt=True, log_tickers=True, 1119 mock.call('fetch_balances',
1120 tag='process_foo__1_print_balances_begin') 1120 {'log_tickers': True, 'add_usdt': True, 'add_portfolio': True},
1121 {'foo': 'bar', 'tag': 'process_foo__1_print_balances_begin'}),
1122 ])
1121 1123
1122 def test_parse_args(self): 1124 def test_parse_args(self):
1123 processor = market.Processor(self.m) 1125 processor = market.Processor(self.m)