Remove Interface V1 support

This commit is contained in:
Matthias 2022-04-25 07:01:27 +02:00
parent 25c6c5e326
commit 562e36c3ec
2 changed files with 15 additions and 31 deletions

View File

@ -217,15 +217,19 @@ class StrategyResolver(IResolver):
raise OperationalException( raise OperationalException(
"`populate_exit_trend` or `populate_sell_trend` must be implemented.") "`populate_exit_trend` or `populate_sell_trend` must be implemented.")
strategy._populate_fun_len = len(getfullargspec(strategy.populate_indicators).args) _populate_fun_len = len(getfullargspec(strategy.populate_indicators).args)
strategy._buy_fun_len = len(getfullargspec(strategy.populate_buy_trend).args) _buy_fun_len = len(getfullargspec(strategy.populate_buy_trend).args)
strategy._sell_fun_len = len(getfullargspec(strategy.populate_sell_trend).args) _sell_fun_len = len(getfullargspec(strategy.populate_sell_trend).args)
if any(x == 2 for x in [ if any(x == 2 for x in [
strategy._populate_fun_len, _populate_fun_len,
strategy._buy_fun_len, _buy_fun_len,
strategy._sell_fun_len _sell_fun_len
]): ]):
strategy.INTERFACE_VERSION = 1 raise OperationalException(
"Strategy Interface v1 is no longer supported. "
"Please update your strategy to implement "
"`populate_indicators`, `populate_entry_trend` and `populate_exit_trend` "
"with the metadata argument. ")
return strategy return strategy
@staticmethod @staticmethod

View File

@ -3,7 +3,6 @@ IStrategy interface
This module defines the interface to apply for strategies This module defines the interface to apply for strategies
""" """
import logging import logging
import warnings
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
from typing import Dict, List, Optional, Tuple, Union from typing import Dict, List, Optional, Tuple, Union
@ -44,14 +43,11 @@ class IStrategy(ABC, HyperStrategyMixin):
""" """
# Strategy interface version # Strategy interface version
# Default to version 2 # Default to version 2
# Version 1 is the initial interface without metadata dict # Version 1 is the initial interface without metadata dict - deprecated and no longer supported.
# Version 2 populate_* include metadata dict # Version 2 populate_* include metadata dict
# Version 3 - First version with short and leverage support # Version 3 - First version with short and leverage support
INTERFACE_VERSION: int = 3 INTERFACE_VERSION: int = 3
_populate_fun_len: int = 0
_buy_fun_len: int = 0
_sell_fun_len: int = 0
_ft_params_from_file: Dict _ft_params_from_file: Dict
# associated minimal roi # associated minimal roi
minimal_roi: Dict = {} minimal_roi: Dict = {}
@ -1090,11 +1086,6 @@ class IStrategy(ABC, HyperStrategyMixin):
dataframe = _create_and_merge_informative_pair( dataframe = _create_and_merge_informative_pair(
self, dataframe, metadata, inf_data, populate_fn) self, dataframe, metadata, inf_data, populate_fn)
if self._populate_fun_len == 2:
warnings.warn("deprecated - check out the Sample strategy to see "
"the current function headers!", DeprecationWarning)
return self.populate_indicators(dataframe) # type: ignore
else:
return self.populate_indicators(dataframe, metadata) return self.populate_indicators(dataframe, metadata)
def advise_entry(self, dataframe: DataFrame, metadata: dict) -> DataFrame: def advise_entry(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
@ -1109,11 +1100,6 @@ class IStrategy(ABC, HyperStrategyMixin):
logger.debug(f"Populating enter signals for pair {metadata.get('pair')}.") logger.debug(f"Populating enter signals for pair {metadata.get('pair')}.")
if self._buy_fun_len == 2:
warnings.warn("deprecated - check out the Sample strategy to see "
"the current function headers!", DeprecationWarning)
df = self.populate_buy_trend(dataframe) # type: ignore
else:
df = self.populate_entry_trend(dataframe, metadata) df = self.populate_entry_trend(dataframe, metadata)
if 'enter_long' not in df.columns: if 'enter_long' not in df.columns:
df = df.rename({'buy': 'enter_long', 'buy_tag': 'enter_tag'}, axis='columns') df = df.rename({'buy': 'enter_long', 'buy_tag': 'enter_tag'}, axis='columns')
@ -1129,13 +1115,7 @@ class IStrategy(ABC, HyperStrategyMixin):
currently traded pair currently traded pair
:return: DataFrame with exit column :return: DataFrame with exit column
""" """
logger.debug(f"Populating exit signals for pair {metadata.get('pair')}.") logger.debug(f"Populating exit signals for pair {metadata.get('pair')}.")
if self._sell_fun_len == 2:
warnings.warn("deprecated - check out the Sample strategy to see "
"the current function headers!", DeprecationWarning)
df = self.populate_sell_trend(dataframe) # type: ignore
else:
df = self.populate_exit_trend(dataframe, metadata) df = self.populate_exit_trend(dataframe, metadata)
if 'exit_long' not in df.columns: if 'exit_long' not in df.columns:
df = df.rename({'sell': 'exit_long'}, axis='columns') df = df.rename({'sell': 'exit_long'}, axis='columns')