Changes based on review comments
This commit is contained in:
		| @@ -79,6 +79,8 @@ class StrategyResolver(IResolver): | |||||||
|                       ("sell_profit_only",                False,       'ask_strategy'), |                       ("sell_profit_only",                False,       'ask_strategy'), | ||||||
|                       ("ignore_roi_if_buy_signal",        False,       'ask_strategy'), |                       ("ignore_roi_if_buy_signal",        False,       'ask_strategy'), | ||||||
|                       ("disable_dataframe_checks",        False,       None), |                       ("disable_dataframe_checks",        False,       None), | ||||||
|  |                       ("ignore_buying_expired_candle",    None,       'ask_strategy'), | ||||||
|  |                       ("ignore_buying_expired_candle_after",  0,       'ask_strategy') | ||||||
|                       ] |                       ] | ||||||
|         for attribute, default, subkey in attributes: |         for attribute, default, subkey in attributes: | ||||||
|             if subkey: |             if subkey: | ||||||
|   | |||||||
| @@ -15,7 +15,7 @@ from pandas import DataFrame | |||||||
| from freqtrade.constants import ListPairsWithTimeframes | from freqtrade.constants import ListPairsWithTimeframes | ||||||
| from freqtrade.data.dataprovider import DataProvider | from freqtrade.data.dataprovider import DataProvider | ||||||
| from freqtrade.exceptions import OperationalException, StrategyError | from freqtrade.exceptions import OperationalException, StrategyError | ||||||
| from freqtrade.exchange import timeframe_to_minutes | from freqtrade.exchange import timeframe_to_minutes, timeframe_to_seconds | ||||||
| from freqtrade.exchange.exchange import timeframe_to_next_date | from freqtrade.exchange.exchange import timeframe_to_next_date | ||||||
| from freqtrade.persistence import PairLocks, Trade | from freqtrade.persistence import PairLocks, Trade | ||||||
| from freqtrade.strategy.strategy_wrapper import strategy_safe_wrapper | from freqtrade.strategy.strategy_wrapper import strategy_safe_wrapper | ||||||
| @@ -481,16 +481,16 @@ class IStrategy(ABC): | |||||||
|         (buy, sell) = latest[SignalType.BUY.value] == 1, latest[SignalType.SELL.value] == 1 |         (buy, sell) = latest[SignalType.BUY.value] == 1, latest[SignalType.SELL.value] == 1 | ||||||
|         logger.debug('trigger: %s (pair=%s) buy=%s sell=%s', |         logger.debug('trigger: %s (pair=%s) buy=%s sell=%s', | ||||||
|                      latest['date'], pair, str(buy), str(sell)) |                      latest['date'], pair, str(buy), str(sell)) | ||||||
|         if self.ignore_expired_candle(dataframe=dataframe, buy=buy): |         timeframe_seconds = timeframe_to_seconds(timeframe) | ||||||
|  |         if self.ignore_expired_candle(latest_date=latest_date, timeframe_seconds=timeframe_seconds, buy=buy): | ||||||
|             return False, sell |             return False, sell | ||||||
|         return buy, sell |         return buy, sell | ||||||
|  |  | ||||||
|     def ignore_expired_candle(self, dataframe: DataFrame, buy: bool): |     def ignore_expired_candle(self, latest_date: datetime, timeframe_seconds: int, buy: bool): | ||||||
|         if self.ignore_buying_expired_candle and buy: |         if self.ignore_buying_expired_candle and buy: | ||||||
|             current_time = datetime.now(timezone.utc) - timedelta( |             current_time = datetime.now(timezone.utc) - timedelta( | ||||||
|                 seconds=self.ignore_buying_expired_candle_after) |                 seconds=self.ignore_buying_expired_candle_after) | ||||||
|             candle_time = dataframe['date'].tail(1).iat[0] |             time_delta = current_time - latest_date + timedelta(seconds=timeframe_seconds) | ||||||
|             time_delta = current_time - candle_time |  | ||||||
|             return time_delta.total_seconds() > self.ignore_buying_expired_candle_after |             return time_delta.total_seconds() > self.ignore_buying_expired_candle_after | ||||||
|         else: |         else: | ||||||
|             return False |             return False | ||||||
|   | |||||||
| @@ -112,15 +112,12 @@ def test_ignore_expired_candle(default_conf, ohlcv_history): | |||||||
|     strategy.ignore_buying_expired_candle = True |     strategy.ignore_buying_expired_candle = True | ||||||
|     strategy.ignore_buying_expired_candle_after = 60 |     strategy.ignore_buying_expired_candle_after = 60 | ||||||
|  |  | ||||||
|     ohlcv_history.loc[-1, 'date'] = arrow.utcnow().shift(minutes=-3) |     ohlcv_history.loc[-1, 'date'] = arrow.utcnow() | ||||||
|     # Take a copy to correctly modify the call |     # Take a copy to correctly modify the call | ||||||
|     mocked_history = ohlcv_history.copy() |     mocked_history = ohlcv_history.copy() | ||||||
|     mocked_history['sell'] = 0 |     latest_date = mocked_history['date'].max() | ||||||
|     mocked_history['buy'] = 0 |  | ||||||
|     mocked_history.loc[1, 'buy'] = 1 |  | ||||||
|     mocked_history.loc[1, 'sell'] = 1 |  | ||||||
|  |  | ||||||
|     assert strategy.ignore_expired_candle(mocked_history, True) is True |     assert strategy.ignore_expired_candle(latest_date=latest_date, timeframe_seconds=300, buy=True) is True | ||||||
|  |  | ||||||
|  |  | ||||||
| def test_assert_df_raise(mocker, caplog, ohlcv_history): | def test_assert_df_raise(mocker, caplog, ohlcv_history): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user