Fix expired candle implementation

Improve and simplify test by passing the current time to the function
This commit is contained in:
Matthias
2021-01-07 07:51:49 +01:00
parent c0f170fdb9
commit b43ef474ad
2 changed files with 16 additions and 9 deletions

View File

@@ -483,16 +483,16 @@ class IStrategy(ABC):
latest['date'], pair, str(buy), str(sell))
timeframe_seconds = timeframe_to_seconds(timeframe)
if self.ignore_expired_candle(latest_date=latest_date,
current_time=datetime.now(timezone.utc),
timeframe_seconds=timeframe_seconds,
buy=buy):
return False, sell
return buy, sell
def ignore_expired_candle(self, latest_date: datetime, timeframe_seconds: int, buy: bool):
def ignore_expired_candle(self, latest_date: datetime, current_time: datetime,
timeframe_seconds: int, buy: bool):
if self.ignore_buying_expired_candle and buy:
current_time = datetime.now(timezone.utc) - timedelta(
seconds=self.ignore_buying_expired_candle_after)
time_delta = current_time - latest_date + timedelta(seconds=timeframe_seconds)
time_delta = current_time - (latest_date + timedelta(seconds=timeframe_seconds))
return time_delta.total_seconds() > self.ignore_buying_expired_candle_after
else:
return False