aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--helper.py7
-rw-r--r--test.py4
2 files changed, 8 insertions, 3 deletions
diff --git a/helper.py b/helper.py
index f1aeaf2..8ef2d64 100644
--- a/helper.py
+++ b/helper.py
@@ -4,10 +4,13 @@ from store import *
4 4
5def move_balances(market, debug=False): 5def move_balances(market, debug=False):
6 needed_in_margin = {} 6 needed_in_margin = {}
7 for currency in BalanceStore.all:
8 if BalanceStore.all[currency].margin_free != 0:
9 needed_in_margin[currency] = 0
7 for trade in TradeStore.all: 10 for trade in TradeStore.all:
11 if trade.value_to.currency not in needed_in_margin:
12 needed_in_margin[trade.value_to.currency] = 0
8 if trade.trade_type == "short": 13 if trade.trade_type == "short":
9 if trade.value_to.currency not in needed_in_margin:
10 needed_in_margin[trade.value_to.currency] = 0
11 needed_in_margin[trade.value_to.currency] += abs(trade.value_to) 14 needed_in_margin[trade.value_to.currency] += abs(trade.value_to)
12 for currency, needed in needed_in_margin.items(): 15 for currency, needed in needed_in_margin.items():
13 current_balance = BalanceStore.all[currency].margin_free 16 current_balance = BalanceStore.all[currency].margin_free
diff --git a/test.py b/test.py
index 26646be..1965521 100644
--- a/test.py
+++ b/test.py
@@ -724,7 +724,8 @@ class HelperTest(WebMockTestCase):
724 portfolio.TradeStore.all = [trade1, trade2, trade3] 724 portfolio.TradeStore.all = [trade1, trade2, trade3]
725 balance1 = portfolio.Balance("BTC", { "margin_free": "0" }) 725 balance1 = portfolio.Balance("BTC", { "margin_free": "0" })
726 balance2 = portfolio.Balance("USDT", { "margin_free": "100" }) 726 balance2 = portfolio.Balance("USDT", { "margin_free": "100" })
727 portfolio.BalanceStore.all = {"BTC": balance1, "USDT": balance2} 727 balance3 = portfolio.Balance("ETC", { "margin_free": "10" })
728 portfolio.BalanceStore.all = {"BTC": balance1, "USDT": balance2, "ETC": balance3}
728 729
729 market = mock.Mock() 730 market = mock.Mock()
730 731
@@ -736,6 +737,7 @@ class HelperTest(WebMockTestCase):
736 else: 737 else:
737 market.transfer_balance.assert_any_call("BTC", 3, "exchange", "margin") 738 market.transfer_balance.assert_any_call("BTC", 3, "exchange", "margin")
738 market.transfer_balance.assert_any_call("USDT", 50, "margin", "exchange") 739 market.transfer_balance.assert_any_call("USDT", 50, "margin", "exchange")
740 market.transfer_balance.assert_any_call("ETC", 10, "margin", "exchange")
739 741
740 @mock.patch.object(helper, "prepare_trades") 742 @mock.patch.object(helper, "prepare_trades")
741 @mock.patch.object(portfolio.TradeStore, "prepare_orders") 743 @mock.patch.object(portfolio.TradeStore, "prepare_orders")