From 71c90422ba5f4c34b8689864d35c92cee0c5e8d5 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 1 May 2020 20:02:38 +0200 Subject: [PATCH] Add explicit test for fee_updated --- freqtrade/persistence.py | 2 ++ tests/test_persistence.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/freqtrade/persistence.py b/freqtrade/persistence.py index a541dcbcc..ea34fd5bf 100644 --- a/freqtrade/persistence.py +++ b/freqtrade/persistence.py @@ -402,6 +402,8 @@ class Trade(_DECL_BASE): return self.fee_open_currency is not None elif side == 'sell': return self.fee_close_currency is not None + else: + return False def _calc_open_trade_price(self) -> float: """ diff --git a/tests/test_persistence.py b/tests/test_persistence.py index 1a42d95fe..5c7686e28 100644 --- a/tests/test_persistence.py +++ b/tests/test_persistence.py @@ -913,6 +913,36 @@ def test_update_fee(fee): assert trade.fee_close == fee_rate +def test_fee_updated(fee): + trade = Trade( + pair='ETH/BTC', + stake_amount=0.001, + fee_open=fee.return_value, + open_date=arrow.utcnow().shift(hours=-2).datetime, + amount=10, + fee_close=fee.return_value, + exchange='bittrex', + open_rate=1, + max_rate=1, + ) + + assert trade.fee_open_currency is None + assert not trade.fee_updated('buy') + assert not trade.fee_updated('sell') + assert not trade.fee_updated('asdf') + + trade.update_fee(0.15, 'BTC', 0.0075, 'buy') + assert trade.fee_updated('buy') + assert not trade.fee_updated('sell') + assert trade.fee_open_currency is not None + assert trade.fee_close_currency is None + + trade.update_fee(0.15, 'ABC', 0.0075, 'sell') + assert trade.fee_updated('buy') + assert trade.fee_updated('sell') + assert not trade.fee_updated('asfd') + + @pytest.mark.usefixtures("init_persistence") def test_total_open_trades_stakes(fee):