From 63c28b651982892e0ad3e1a26766090b7886f71a Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 28 Apr 2021 16:00:12 +0200 Subject: [PATCH] Remove obsolete get_balance method --- freqtrade/exchange/exchange.py | 11 ----------- tests/exchange/test_exchange.py | 23 ----------------------- tests/test_freqtradebot.py | 16 +--------------- 3 files changed, 1 insertion(+), 49 deletions(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 80b392d73..f61f89fcb 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -666,17 +666,6 @@ class Exchange: raise OperationalException(f"stoploss is not implemented for {self.name}.") - @retrier - def get_balance(self, currency: str) -> float: - - # ccxt exception is already handled by get_balances - balances = self.get_balances() - balance = balances.get(currency) - if balance is None: - raise TemporaryError( - f'Could not get {currency} balance due to malformed exchange response: {balances}') - return balance['free'] - @retrier def get_balances(self) -> dict: diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py index 27f4d0db9..573f41bda 100644 --- a/tests/exchange/test_exchange.py +++ b/tests/exchange/test_exchange.py @@ -1248,29 +1248,6 @@ def test_sell_considers_time_in_force(default_conf, mocker, exchange_name): assert "timeInForce" not in api_mock.create_order.call_args[0][5] -@pytest.mark.parametrize("exchange_name", EXCHANGES) -def test_get_balance_prod(default_conf, mocker, exchange_name): - api_mock = MagicMock() - api_mock.fetch_balance = MagicMock(return_value={'BTC': {'free': 123.4, 'total': 123.4}}) - default_conf['dry_run'] = False - - exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name) - - assert exchange.get_balance(currency='BTC') == 123.4 - - with pytest.raises(OperationalException): - api_mock.fetch_balance = MagicMock(side_effect=ccxt.BaseError("Unknown error")) - exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name) - - exchange.get_balance(currency='BTC') - - with pytest.raises(TemporaryError, match=r'.*balance due to malformed exchange response:.*'): - exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name) - mocker.patch('freqtrade.exchange.Exchange.get_balances', MagicMock(return_value={})) - mocker.patch('freqtrade.exchange.Kraken.get_balances', MagicMock(return_value={})) - exchange.get_balance(currency='BTC') - - @pytest.mark.parametrize("exchange_name", EXCHANGES) def test_get_balances_prod(default_conf, mocker, exchange_name): balance_item = { diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index ad000515e..2c6e86cf3 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -82,10 +82,6 @@ def test_bot_cleanup(mocker, default_conf, caplog) -> None: def test_order_dict_dry_run(default_conf, mocker, caplog) -> None: patch_RPCManager(mocker) patch_exchange(mocker) - mocker.patch.multiple( - 'freqtrade.exchange.Exchange', - get_balance=MagicMock(return_value=default_conf['stake_amount'] * 2) - ) conf = default_conf.copy() conf['runmode'] = RunMode.DRY_RUN conf['order_types'] = { @@ -117,10 +113,7 @@ def test_order_dict_dry_run(default_conf, mocker, caplog) -> None: def test_order_dict_live(default_conf, mocker, caplog) -> None: patch_RPCManager(mocker) patch_exchange(mocker) - mocker.patch.multiple( - 'freqtrade.exchange.Exchange', - get_balance=MagicMock(return_value=default_conf['stake_amount'] * 2) - ) + conf = default_conf.copy() conf['runmode'] = RunMode.LIVE conf['order_types'] = { @@ -153,10 +146,6 @@ def test_order_dict_live(default_conf, mocker, caplog) -> None: def test_get_trade_stake_amount(default_conf, ticker, mocker) -> None: patch_RPCManager(mocker) patch_exchange(mocker) - mocker.patch.multiple( - 'freqtrade.exchange.Exchange', - get_balance=MagicMock(return_value=default_conf['stake_amount'] * 2) - ) freqtrade = FreqtradeBot(default_conf) @@ -181,7 +170,6 @@ def test_check_available_stake_amount(default_conf, ticker, mocker, fee, limit_b mocker.patch.multiple( 'freqtrade.exchange.Exchange', fetch_ticker=ticker, - get_balance=MagicMock(return_value=default_conf['stake_amount'] * 2), buy=MagicMock(return_value=limit_buy_order_open), get_fee=fee ) @@ -435,7 +423,6 @@ def test_create_trade_limit_reached(default_conf, ticker, limit_buy_order_open, 'freqtrade.exchange.Exchange', fetch_ticker=ticker, buy=MagicMock(return_value=limit_buy_order_open), - get_balance=MagicMock(return_value=default_conf['stake_amount']), get_fee=fee, ) default_conf['max_open_trades'] = 0 @@ -523,7 +510,6 @@ def test_create_trade_no_signal(default_conf, fee, mocker) -> None: patch_exchange(mocker) mocker.patch.multiple( 'freqtrade.exchange.Exchange', - get_balance=MagicMock(return_value=20), get_fee=fee, ) default_conf['stake_amount'] = 10