Added enter_side and exit_side computed variables to persistence

This commit is contained in:
Sam Germain 2021-07-17 01:57:57 -06:00
parent b801eaaa54
commit a900570f1a
2 changed files with 18 additions and 0 deletions

View File

@ -297,6 +297,20 @@ class LocalTrade():
def close_date_utc(self): def close_date_utc(self):
return self.close_date.replace(tzinfo=timezone.utc) 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): def __init__(self, **kwargs):
for key in kwargs: for key in kwargs:
setattr(self, key, kwargs[key]) setattr(self, key, kwargs[key])

View File

@ -83,6 +83,8 @@ def test_is_opening_closing_trade(fee):
assert trade.is_opening_trade('sell') is False assert trade.is_opening_trade('sell') is False
assert trade.is_closing_trade('buy') is False assert trade.is_closing_trade('buy') is False
assert trade.is_closing_trade('sell') is True assert trade.is_closing_trade('sell') is True
assert trade.enter_side == 'buy'
assert trade.exit_side == 'sell'
trade = Trade( trade = Trade(
id=2, id=2,
@ -103,6 +105,8 @@ def test_is_opening_closing_trade(fee):
assert trade.is_opening_trade('sell') is True assert trade.is_opening_trade('sell') is True
assert trade.is_closing_trade('buy') is True assert trade.is_closing_trade('buy') is True
assert trade.is_closing_trade('sell') is False assert trade.is_closing_trade('sell') is False
assert trade.enter_side == 'sell'
assert trade.exit_side == 'buy'
@pytest.mark.usefixtures("init_persistence") @pytest.mark.usefixtures("init_persistence")