SellType -> ExitType

This commit is contained in:
Sam Germain
2022-01-04 22:56:15 -06:00
parent f5805543ed
commit e9d3903827
22 changed files with 211 additions and 211 deletions

View File

@@ -13,7 +13,7 @@ from pandas import DataFrame
from freqtrade.constants import ListPairsWithTimeframes
from freqtrade.data.dataprovider import DataProvider
from freqtrade.enums import CandleType, SellType, SignalDirection, SignalTagType, SignalType
from freqtrade.enums import CandleType, ExitType, SignalDirection, SignalTagType, SignalType
from freqtrade.exceptions import OperationalException, StrategyError
from freqtrade.exchange import timeframe_to_minutes, timeframe_to_seconds
from freqtrade.exchange.exchange import timeframe_to_next_date
@@ -34,16 +34,16 @@ class SellCheckTuple:
"""
NamedTuple for Sell type + reason
"""
sell_type: SellType
sell_type: ExitType
exit_reason: str = ''
def __init__(self, sell_type: SellType, exit_reason: str = ''):
def __init__(self, sell_type: ExitType, exit_reason: str = ''):
self.sell_type = sell_type
self.exit_reason = exit_reason or sell_type.value
@property
def sell_flag(self):
return self.sell_type != SellType.NONE
return self.sell_type != ExitType.NONE
class IStrategy(ABC, HyperStrategyMixin):
@@ -784,7 +784,7 @@ class IStrategy(ABC, HyperStrategyMixin):
and self.min_roi_reached(trade=trade, current_profit=current_profit,
current_time=date))
sell_signal = SellType.NONE
sell_signal = ExitType.NONE
custom_reason = ''
# use provided rate in backtesting, not high/low.
current_rate = rate
@@ -795,14 +795,14 @@ class IStrategy(ABC, HyperStrategyMixin):
pass
elif self.use_exit_signal and not enter:
if exit_:
sell_signal = SellType.SELL_SIGNAL
sell_signal = ExitType.SELL_SIGNAL
else:
trade_type = "exit_short" if trade.is_short else "sell"
custom_reason = strategy_safe_wrapper(self.custom_sell, default_retval=False)(
pair=trade.pair, trade=trade, current_time=date, current_rate=current_rate,
current_profit=current_profit)
if custom_reason:
sell_signal = SellType.CUSTOM_SELL
sell_signal = ExitType.CUSTOM_SELL
if isinstance(custom_reason, str):
if len(custom_reason) > CUSTOM_SELL_MAX_LENGTH:
logger.warning(f'Custom {trade_type} reason returned from '
@@ -811,9 +811,9 @@ class IStrategy(ABC, HyperStrategyMixin):
custom_reason = custom_reason[:CUSTOM_SELL_MAX_LENGTH]
else:
custom_reason = None
if sell_signal in (SellType.CUSTOM_SELL, SellType.SELL_SIGNAL):
if sell_signal in (ExitType.CUSTOM_SELL, ExitType.SELL_SIGNAL):
logger.debug(f"{trade.pair} - Sell signal received. "
f"sell_type=SellType.{sell_signal.name}" +
f"sell_type=ExitType.{sell_signal.name}" +
(f", custom_reason={custom_reason}" if custom_reason else ""))
return SellCheckTuple(sell_type=sell_signal, exit_reason=custom_reason)
@@ -821,9 +821,9 @@ class IStrategy(ABC, HyperStrategyMixin):
# Exit-signal
# ROI (if not stoploss)
# Stoploss
if roi_reached and stoplossflag.sell_type != SellType.STOP_LOSS:
logger.debug(f"{trade.pair} - Required profit reached. sell_type=SellType.ROI")
return SellCheckTuple(sell_type=SellType.ROI)
if roi_reached and stoplossflag.sell_type != ExitType.STOP_LOSS:
logger.debug(f"{trade.pair} - Required profit reached. sell_type=ExitType.ROI")
return SellCheckTuple(sell_type=ExitType.ROI)
if stoplossflag.sell_flag:
@@ -832,7 +832,7 @@ class IStrategy(ABC, HyperStrategyMixin):
# This one is noisy, commented out...
# logger.debug(f"{trade.pair} - No exit signal.")
return SellCheckTuple(sell_type=SellType.NONE)
return SellCheckTuple(sell_type=ExitType.NONE)
def stop_loss_reached(self, current_rate: float, trade: Trade,
current_time: datetime, current_profit: float,
@@ -896,11 +896,11 @@ class IStrategy(ABC, HyperStrategyMixin):
if ((sl_higher_short or sl_lower_long) and
(not self.order_types.get('stoploss_on_exchange') or self.config['dry_run'])):
sell_type = SellType.STOP_LOSS
sell_type = ExitType.STOP_LOSS
# If initial stoploss is not the same as current one then it is trailing.
if trade.initial_stop_loss != trade.stop_loss:
sell_type = SellType.TRAILING_STOP_LOSS
sell_type = ExitType.TRAILING_STOP_LOSS
logger.debug(
f"{trade.pair} - HIT STOP: current price at "
f"{((high if trade.is_short else low) or current_rate):.6f}, "
@@ -917,7 +917,7 @@ class IStrategy(ABC, HyperStrategyMixin):
return SellCheckTuple(sell_type=sell_type)
return SellCheckTuple(sell_type=SellType.NONE)
return SellCheckTuple(sell_type=ExitType.NONE)
def min_roi_reached_entry(self, trade_dur: int) -> Tuple[Optional[int], Optional[float]]:
"""