aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2018-02-12 14:11:02 +0100
committerIsmaël Bouya <ismael.bouya@normalesup.org>2018-02-12 14:11:02 +0100
commit97922ff1826cc6b9c0329cc30e8d4621bb2644ee (patch)
tree1437590a98b10f64683e226d03fda130840f0ba6
parent9f54fd9acf98692ff7601fd3236c46745eb26e15 (diff)
downloadTrader-97922ff1826cc6b9c0329cc30e8d4621bb2644ee.tar.gz
Trader-97922ff1826cc6b9c0329cc30e8d4621bb2644ee.tar.zst
Trader-97922ff1826cc6b9c0329cc30e8d4621bb2644ee.zip
Add print_balances helper
-rw-r--r--helper.py8
-rw-r--r--portfolio.py2
-rw-r--r--test.py26
3 files changed, 36 insertions, 0 deletions
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"):
118 print(balance) 118 print(balance)
119 TradeStore.print_all_with_order() 119 TradeStore.print_all_with_order()
120 120
121def print_balances(market, base_currency="BTC"):
122 BalanceStore.fetch_balances(market)
123 for currency, balance in BalanceStore.all.items():
124 print(balance)
125 if base_currency is not None:
126 print("total:")
127 print(sum(BalanceStore.in_currency(base_currency, market).values()))
128
121def process_sell_needed__1_sell(market, base_currency="BTC", debug=False): 129def process_sell_needed__1_sell(market, base_currency="BTC", debug=False):
122 prepare_trades(market, base_currency=base_currency, debug=debug) 130 prepare_trades(market, base_currency=base_currency, debug=debug)
123 TradeStore.prepare_orders(compute_value="average", only="dispose") 131 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:
345 ticker = ticker["original"] 345 ticker = ticker["original"]
346 rate = Computation.compute_value(ticker, self.order_action(inverted), compute_value=compute_value) 346 rate = Computation.compute_value(ticker, self.order_action(inverted), compute_value=compute_value)
347 347
348 # FIXME: Dust amount should be removed from there if they werent
349 # honored in other sales
348 delta_in_base = abs(self.value_from - self.value_to) 350 delta_in_base = abs(self.value_from - self.value_to)
349 # 9 BTC's worth of move (10 - 1 or 1 - 10 depending on case) 351 # 9 BTC's worth of move (10 - 1 or 1 - 10 depending on case)
350 352
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):
820 print_all_with_order.assert_called() 820 print_all_with_order.assert_called()
821 self.assertRegex(stdout_mock.getvalue(), "Balance") 821 self.assertRegex(stdout_mock.getvalue(), "Balance")
822 822
823 @mock.patch.object(portfolio.BalanceStore, "fetch_balances")
824 @mock.patch.object(portfolio.BalanceStore, "in_currency")
825 @mock.patch('sys.stdout', new_callable=StringIO)
826 def test_print_balances(self, stdout_mock, in_currency, fetch_balances):
827 market = mock.Mock()
828 portfolio.BalanceStore.all = {
829 "BTC": portfolio.Balance("BTC", {
830 "total": "0.65",
831 "exchange_total":"0.65",
832 "exchange_free": "0.35",
833 "exchange_used": "0.30"}),
834 "ETH": portfolio.Balance("ETH", {
835 "total": 3,
836 "exchange_total": 3,
837 "exchange_free": 3,
838 "exchange_used": 0}),
839 }
840 in_currency.return_value = {
841 "BTC": portfolio.Amount("BTC", "0.65"),
842 "ETH": portfolio.Amount("BTC", "0.3"),
843 }
844 helper.print_balances(market)
845 fetch_balances.assert_called_with(market)
846 self.assertRegex(stdout_mock.getvalue(), "Balance")
847 self.assertRegex(stdout_mock.getvalue(), "0.95000000 BTC")
848
823 @mock.patch.object(helper, "prepare_trades") 849 @mock.patch.object(helper, "prepare_trades")
824 @mock.patch.object(helper, "follow_orders") 850 @mock.patch.object(helper, "follow_orders")
825 @mock.patch.object(portfolio.TradeStore, "prepare_orders") 851 @mock.patch.object(portfolio.TradeStore, "prepare_orders")