From 97922ff1826cc6b9c0329cc30e8d4621bb2644ee Mon Sep 17 00:00:00 2001 From: =?utf8?q?Isma=C3=ABl=20Bouya?= Date: Mon, 12 Feb 2018 14:11:02 +0100 Subject: [PATCH] Add print_balances helper --- helper.py | 8 ++++++++ portfolio.py | 2 ++ test.py | 26 ++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/helper.py b/helper.py index 8ef2d64..3e39785 100644 --- a/helper.py +++ b/helper.py @@ -118,6 +118,14 @@ def print_orders(market, base_currency="BTC"): print(balance) TradeStore.print_all_with_order() +def print_balances(market, base_currency="BTC"): + BalanceStore.fetch_balances(market) + for currency, balance in BalanceStore.all.items(): + print(balance) + if base_currency is not None: + print("total:") + print(sum(BalanceStore.in_currency(base_currency, market).values())) + def process_sell_needed__1_sell(market, base_currency="BTC", debug=False): prepare_trades(market, base_currency=base_currency, debug=debug) TradeStore.prepare_orders(compute_value="average", only="dispose") diff --git a/portfolio.py b/portfolio.py index b77f975..482d0da 100644 --- a/portfolio.py +++ b/portfolio.py @@ -345,6 +345,8 @@ class Trade: ticker = ticker["original"] rate = Computation.compute_value(ticker, self.order_action(inverted), compute_value=compute_value) + # FIXME: Dust amount should be removed from there if they werent + # honored in other sales delta_in_base = abs(self.value_from - self.value_to) # 9 BTC's worth of move (10 - 1 or 1 - 10 depending on case) diff --git a/test.py b/test.py index 56167f4..8641130 100644 --- a/test.py +++ b/test.py @@ -820,6 +820,32 @@ class HelperTest(WebMockTestCase): print_all_with_order.assert_called() self.assertRegex(stdout_mock.getvalue(), "Balance") + @mock.patch.object(portfolio.BalanceStore, "fetch_balances") + @mock.patch.object(portfolio.BalanceStore, "in_currency") + @mock.patch('sys.stdout', new_callable=StringIO) + def test_print_balances(self, stdout_mock, in_currency, fetch_balances): + market = mock.Mock() + portfolio.BalanceStore.all = { + "BTC": portfolio.Balance("BTC", { + "total": "0.65", + "exchange_total":"0.65", + "exchange_free": "0.35", + "exchange_used": "0.30"}), + "ETH": portfolio.Balance("ETH", { + "total": 3, + "exchange_total": 3, + "exchange_free": 3, + "exchange_used": 0}), + } + in_currency.return_value = { + "BTC": portfolio.Amount("BTC", "0.65"), + "ETH": portfolio.Amount("BTC", "0.3"), + } + helper.print_balances(market) + fetch_balances.assert_called_with(market) + self.assertRegex(stdout_mock.getvalue(), "Balance") + self.assertRegex(stdout_mock.getvalue(), "0.95000000 BTC") + @mock.patch.object(helper, "prepare_trades") @mock.patch.object(helper, "follow_orders") @mock.patch.object(portfolio.TradeStore, "prepare_orders") -- 2.41.0