Skip to content

Commit efcac2a

Browse files
committed
Fix kraken get_balance currency/alternate_currency
1 parent a8f3eab commit efcac2a

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

balancer.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(self):
5454

5555
try:
5656
props = config['config']
57-
self.bot_version = '1.5.0'
57+
self.bot_version = '1.5.1'
5858
self.exchange = str(props['exchange']).strip('"').lower()
5959
self.api_key = str(props['api_key']).strip('"')
6060
self.api_secret = str(props['api_secret']).strip('"')
@@ -1532,13 +1532,17 @@ def get_fiat_balance():
15321532

15331533
def get_balance(currency: str):
15341534
try:
1535+
alt_currency = ''
15351536
if CONF.exchange == 'kraken':
15361537
if currency == 'BTC':
1537-
currency = 'XBT'
1538-
currency += '.F'
1538+
alt_currency = 'XBT.F'
1539+
else:
1540+
alt_currency = currency + '.F'
15391541
balance_result = {'free': 0, 'used': 0, 'total': 0}
15401542
bal = EXCHANGE.fetch_balance()
1541-
if currency in bal and bal[currency]:
1543+
if currency in bal or alt_currency in bal:
1544+
if alt_currency in bal and bal[alt_currency]['total'] > 0:
1545+
currency = alt_currency
15421546
if 'free' in bal[currency]:
15431547
balance_result['free'] = bal[currency]['free'] or 0
15441548
if 'used' in bal[currency]:

balancer_test.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,22 @@ def test_get_balance(self, mock_fetch_balance, mock_logging):
927927
balancer.CONF.test = False
928928
balancer.LOG = mock_logging
929929
balancer.EXCHANGE = balancer.connect_to_exchange()
930-
mock_fetch_balance.return_value = {'XBT.F': {'used': None, 'free': None, 'total': 0.9}}
930+
mock_fetch_balance.return_value = {'BTC': {'used': None, 'free': None, 'total': 0.9}, 'XBT.F': {'total': 0}}
931+
932+
balance = balancer.get_crypto_balance()
933+
934+
self.assertEqual(0, balance['used'])
935+
self.assertEqual(0, balance['free'])
936+
self.assertEqual(0.9, balance['total'])
937+
938+
@patch('balancer.logging')
939+
@mock.patch.object(ccxt.kraken, 'fetch_balance')
940+
def test_get_balance_alternative_currency(self, mock_fetch_balance, mock_logging):
941+
balancer.CONF = self.create_default_conf()
942+
balancer.CONF.test = False
943+
balancer.LOG = mock_logging
944+
balancer.EXCHANGE = balancer.connect_to_exchange()
945+
mock_fetch_balance.return_value = {'BTC': {'total': 0}, 'XBT.F': {'used': None, 'free': None, 'total': 0.9}}
931946

932947
balance = balancer.get_crypto_balance()
933948

0 commit comments

Comments
 (0)