move initial logic to persistence

This commit is contained in:
xmatthias
2018-06-27 06:38:49 +02:00
committed by creslinux
parent 6f458d7a18
commit 52a7a31e7c
3 changed files with 25 additions and 10 deletions

View File

@@ -167,15 +167,19 @@ class Trade(_DECL_BASE):
arrow.get(self.open_date).humanize() if self.is_open else 'closed'
)
def adjust_stop_loss(self, current_price, stoploss):
def adjust_stop_loss(self, current_price: float, stoploss: float, initial: bool =False):
"""
this adjusts the stop loss to it's most recently observed
setting
this adjusts the stop loss to it's most recently observed setting
:param current_price:
:param stoploss:
:param stoploss in percent:
:param initial:
:return:
"""
if initial and not (self.stop_loss is None or self.stop_loss == 0):
# Don't modify if called with initial and nothing to do
return
new_loss = float(current_price * (1 - abs(stoploss)))
# keeping track of the highest observed rate for this trade