From 4b06c9e0aeb03bb2fcbf1c3dc260c09fccd95edb Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 22 Sep 2020 19:37:18 +0200 Subject: [PATCH 1/2] Add test verifying wrong behaviour --- tests/test_wallets.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/test_wallets.py b/tests/test_wallets.py index 884470014..450dabc4d 100644 --- a/tests/test_wallets.py +++ b/tests/test_wallets.py @@ -19,12 +19,17 @@ def test_sync_wallet_at_boot(mocker, default_conf): "used": 0.0, "total": 0.260739 }, + "USDT": { + "free": 20, + "used": 20, + "total": 40 + }, }) ) freqtrade = get_patched_freqtradebot(mocker, default_conf) - assert len(freqtrade.wallets._wallets) == 2 + assert len(freqtrade.wallets._wallets) == 3 assert freqtrade.wallets._wallets['BNT'].free == 1.0 assert freqtrade.wallets._wallets['BNT'].used == 2.0 assert freqtrade.wallets._wallets['BNT'].total == 3.0 @@ -32,6 +37,7 @@ def test_sync_wallet_at_boot(mocker, default_conf): assert freqtrade.wallets._wallets['GAS'].used == 0.0 assert freqtrade.wallets._wallets['GAS'].total == 0.260739 assert freqtrade.wallets.get_free('BNT') == 1.0 + assert 'USDT' in freqtrade.wallets._wallets assert freqtrade.wallets._last_wallet_refresh > 0 mocker.patch.multiple( 'freqtrade.exchange.Exchange', @@ -51,6 +57,7 @@ def test_sync_wallet_at_boot(mocker, default_conf): freqtrade.wallets.update() + # USDT is missing from the 2nd result - so should not be in this either. assert len(freqtrade.wallets._wallets) == 2 assert freqtrade.wallets._wallets['BNT'].free == 1.2 assert freqtrade.wallets._wallets['BNT'].used == 1.9 From 6b46a35b19737009db78ca82c843a550a64a6243 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 22 Sep 2020 19:37:31 +0200 Subject: [PATCH 2/2] Fix bug of balances not disappearing --- freqtrade/wallets.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/freqtrade/wallets.py b/freqtrade/wallets.py index b913155bc..ac08f337c 100644 --- a/freqtrade/wallets.py +++ b/freqtrade/wallets.py @@ -2,6 +2,7 @@ """ Wallet """ import logging +from copy import deepcopy from typing import Any, Dict, NamedTuple import arrow @@ -93,6 +94,10 @@ class Wallets: balances[currency].get('used', None), balances[currency].get('total', None) ) + # Remove currencies no longer in get_balances output + for currency in deepcopy(self._wallets): + if currency not in balances: + del self._wallets[currency] def update(self, require_update: bool = True) -> None: """