From 54bde6ac11a183be414a8faa37e588eafa269aaf Mon Sep 17 00:00:00 2001 From: Yazeed Al Oyoun Date: Wed, 11 Mar 2020 16:34:23 +0100 Subject: [PATCH] verify date on new candle before producing signal --- freqtrade/freqtradebot.py | 9 ++++++--- freqtrade/strategy/interface.py | 9 +++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 914b8d9cd..02d8b5b56 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -390,14 +390,17 @@ class FreqtradeBot: """ logger.debug(f"create_trade for pair {pair}") + dataframe = self.dataprovider.ohlcv(pair, self.strategy.ticker_interval) + latest = dataframe.iloc[-1] + # Check if dataframe is out of date + signal_date = arrow.get(latest['date']) + if self.strategy.is_pair_locked(pair): logger.info(f"Pair {pair} is currently locked.") return False # running get_signal on historical data fetched - (buy, sell) = self.strategy.get_signal( - pair, self.strategy.ticker_interval, - self.dataprovider.ohlcv(pair, self.strategy.ticker_interval)) + (buy, sell) = self.strategy.get_signal(pair, self.strategy.ticker_interval, dataframe) if buy and not sell: if not self.get_free_open_trades(): diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index d23af3f6e..765e23b0b 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -277,15 +277,20 @@ class IStrategy(ABC): latest = dataframe.iloc[-1] - # Check if dataframe is out of date + # Check if dataframe has new candle signal_date = arrow.get(latest['date']) interval_minutes = timeframe_to_minutes(interval) + if (arrow.utcnow() - signal_date).total_seconds() // 60 >= interval_minutes: + logger.warning('Old candle for pair %s. Last tick is %s minutes old', + pair, (arrow.utcnow() - signal_date).total_seconds() // 60) + + # Check if dataframe is out of date offset = self.config.get('exchange', {}).get('outdated_offset', 5) if signal_date < (arrow.utcnow().shift(minutes=-(interval_minutes * 2 + offset))): logger.warning( 'Outdated history for pair %s. Last tick is %s minutes old', pair, - (arrow.utcnow() - signal_date).seconds // 60 + (arrow.utcnow() - signal_date).total_seconds() // 60 ) return False, False