mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
Fix some type errors
This commit is contained in:
parent
f9f32a15bb
commit
f3b6a0a797
|
@ -700,22 +700,22 @@ class FreqtradeBot(LoggingMixin):
|
|||
|
||||
logger.debug('Handling %s ...', trade)
|
||||
|
||||
(buy, sell) = (False, False)
|
||||
(enter, exit_) = (False, False)
|
||||
|
||||
if (self.config.get('use_sell_signal', True) or
|
||||
self.config.get('ignore_roi_if_buy_signal', False)):
|
||||
analyzed_df, _ = self.dataprovider.get_analyzed_dataframe(trade.pair,
|
||||
self.strategy.timeframe)
|
||||
|
||||
(buy, sell) = self.strategy.get_exit_signal(
|
||||
(enter, exit_) = self.strategy.get_exit_signal(
|
||||
trade.pair,
|
||||
self.strategy.timeframe,
|
||||
analyzed_df
|
||||
)
|
||||
|
||||
logger.debug('checking sell')
|
||||
# TODO-lev: side should depend on trade side.
|
||||
sell_rate = self.exchange.get_rate(trade.pair, refresh=True, side="sell")
|
||||
if self._check_and_execute_sell(trade, sell_rate, buy, sell):
|
||||
if self._check_and_execute_exit(trade, sell_rate, enter, exit_):
|
||||
return True
|
||||
|
||||
logger.debug('Found no sell signal for %s.', trade)
|
||||
|
@ -852,18 +852,18 @@ class FreqtradeBot(LoggingMixin):
|
|||
logger.warning(f"Could not create trailing stoploss order "
|
||||
f"for pair {trade.pair}.")
|
||||
|
||||
def _check_and_execute_sell(self, trade: Trade, sell_rate: float,
|
||||
buy: bool, sell: bool) -> bool:
|
||||
def _check_and_execute_exit(self, trade: Trade, sell_rate: float,
|
||||
enter: bool, exit_: bool) -> bool:
|
||||
"""
|
||||
Check and execute sell
|
||||
Check and execute trade exit
|
||||
"""
|
||||
should_exit: SellCheckTuple = self.strategy.should_exit(
|
||||
trade, sell_rate, datetime.now(timezone.utc), buy, sell,
|
||||
trade, sell_rate, datetime.now(timezone.utc), enter, exit_,
|
||||
force_stoploss=self.edge.stoploss(trade.pair) if self.edge else 0
|
||||
)
|
||||
|
||||
if should_exit.sell_flag:
|
||||
logger.info(f'Executing Sell for {trade.pair}. Reason: {should_exit.sell_type}')
|
||||
logger.info(f'Exit for {trade.pair} detected. Reason: {should_exit.sell_type}')
|
||||
self.execute_sell(trade, sell_rate, should_exit)
|
||||
return True
|
||||
return False
|
||||
|
|
|
@ -543,7 +543,7 @@ class IStrategy(ABC, HyperStrategyMixin):
|
|||
pair: str,
|
||||
timeframe: str,
|
||||
dataframe: DataFrame,
|
||||
) -> Tuple[Optional[DataFrame], arrow.Arrow]:
|
||||
) -> Tuple[Optional[DataFrame], Optional[arrow.Arrow]]:
|
||||
"""
|
||||
Get the latest candle. Used only during real mode
|
||||
:param pair: pair in format ANT/BTC
|
||||
|
@ -553,7 +553,7 @@ class IStrategy(ABC, HyperStrategyMixin):
|
|||
"""
|
||||
if not isinstance(dataframe, DataFrame) or dataframe.empty:
|
||||
logger.warning(f'Empty candle (OHLCV) data for pair {pair}')
|
||||
return False, False, None
|
||||
return None, None
|
||||
|
||||
latest_date = dataframe['date'].max()
|
||||
latest = dataframe.loc[dataframe['date'] == latest_date].iloc[-1]
|
||||
|
@ -591,7 +591,7 @@ class IStrategy(ABC, HyperStrategyMixin):
|
|||
"""
|
||||
latest, latest_date = self.get_latest_candle(pair, timeframe, dataframe)
|
||||
if latest is None:
|
||||
return False, False, None
|
||||
return False, False
|
||||
|
||||
if is_short:
|
||||
enter = latest[SignalType.SHORT] == 1
|
||||
|
@ -621,8 +621,8 @@ class IStrategy(ABC, HyperStrategyMixin):
|
|||
:return: (SignalDirection, entry_tag)
|
||||
"""
|
||||
latest, latest_date = self.get_latest_candle(pair, timeframe, dataframe)
|
||||
if latest is None:
|
||||
return False, False, None
|
||||
if latest is None or latest_date is None:
|
||||
return None, None
|
||||
|
||||
enter_long = latest[SignalType.BUY] == 1
|
||||
exit_long = latest[SignalType.SELL] == 1
|
||||
|
@ -630,7 +630,7 @@ class IStrategy(ABC, HyperStrategyMixin):
|
|||
exit_short = latest[SignalType.EXIT_SHORT] == 1
|
||||
|
||||
enter_signal: Optional[SignalDirection] = None
|
||||
enter_tag_value = None
|
||||
enter_tag_value: Optional[str] = None
|
||||
if enter_long == 1 and not any([exit_long, enter_short]):
|
||||
enter_signal = SignalDirection.LONG
|
||||
enter_tag_value = latest.get(SignalTagType.BUY_TAG, None)
|
||||
|
@ -641,12 +641,12 @@ class IStrategy(ABC, HyperStrategyMixin):
|
|||
timeframe_seconds = timeframe_to_seconds(timeframe)
|
||||
|
||||
if self.ignore_expired_candle(
|
||||
latest_date=latest_date,
|
||||
latest_date=latest_date.datetime,
|
||||
current_time=datetime.now(timezone.utc),
|
||||
timeframe_seconds=timeframe_seconds,
|
||||
enter=enter_signal
|
||||
enter=bool(enter_signal)
|
||||
):
|
||||
return False, enter_tag_value
|
||||
return None, enter_tag_value
|
||||
|
||||
logger.debug(f"entry trigger: {latest['date']} (pair={pair}) "
|
||||
f"enter={enter_long} enter_tag_value={enter_tag_value}")
|
||||
|
|
Loading…
Reference in New Issue
Block a user