Added enter_side and exit_side computed variables to persistence
This commit is contained in:
parent
b801eaaa54
commit
a900570f1a
@ -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])
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user