From a900570f1afc7c28b06123b3aff60dc22d2fca71 Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Sat, 17 Jul 2021 01:57:57 -0600 Subject: [PATCH] Added enter_side and exit_side computed variables to persistence --- freqtrade/persistence/models.py | 14 ++++++++++++++ tests/persistence/test_persistence.py | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/freqtrade/persistence/models.py b/freqtrade/persistence/models.py index 69a103123..3500b9c8a 100644 --- a/freqtrade/persistence/models.py +++ b/freqtrade/persistence/models.py @@ -297,6 +297,20 @@ class LocalTrade(): def close_date_utc(self): return self.close_date.replace(tzinfo=timezone.utc) + @property + def enter_side(self) -> str: + if self.is_short: + return "sell" + else: + return "buy" + + @property + def exit_side(self) -> str: + if self.is_short: + return "buy" + else: + return "sell" + def __init__(self, **kwargs): for key in kwargs: setattr(self, key, kwargs[key]) diff --git a/tests/persistence/test_persistence.py b/tests/persistence/test_persistence.py index cf1ed0121..913a40ca1 100644 --- a/tests/persistence/test_persistence.py +++ b/tests/persistence/test_persistence.py @@ -83,6 +83,8 @@ def test_is_opening_closing_trade(fee): assert trade.is_opening_trade('sell') is False assert trade.is_closing_trade('buy') is False assert trade.is_closing_trade('sell') is True + assert trade.enter_side == 'buy' + assert trade.exit_side == 'sell' trade = Trade( id=2, @@ -103,6 +105,8 @@ def test_is_opening_closing_trade(fee): assert trade.is_opening_trade('sell') is True assert trade.is_closing_trade('buy') is True assert trade.is_closing_trade('sell') is False + assert trade.enter_side == 'sell' + assert trade.exit_side == 'buy' @pytest.mark.usefixtures("init_persistence")