mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-11-29 08:33:07 +00:00
fix: only evaluate the same exit-reason once
Limit this behavior to if it caused an actual exit.
This commit is contained in:
@@ -64,7 +64,7 @@ from freqtrade.rpc.rpc_types import (
|
|||||||
)
|
)
|
||||||
from freqtrade.strategy.interface import IStrategy
|
from freqtrade.strategy.interface import IStrategy
|
||||||
from freqtrade.strategy.strategy_wrapper import strategy_safe_wrapper
|
from freqtrade.strategy.strategy_wrapper import strategy_safe_wrapper
|
||||||
from freqtrade.util import FtPrecise, MeasureTime, dt_from_ts
|
from freqtrade.util import FtPrecise, MeasureTime, PeriodicCache, dt_from_ts, dt_now
|
||||||
from freqtrade.util.migrations.binance_mig import migrate_binance_futures_names
|
from freqtrade.util.migrations.binance_mig import migrate_binance_futures_names
|
||||||
from freqtrade.wallets import Wallets
|
from freqtrade.wallets import Wallets
|
||||||
|
|
||||||
@@ -154,6 +154,7 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
# Protect exit-logic from forcesell and vice versa
|
# Protect exit-logic from forcesell and vice versa
|
||||||
self._exit_lock = Lock()
|
self._exit_lock = Lock()
|
||||||
timeframe_secs = timeframe_to_seconds(self.strategy.timeframe)
|
timeframe_secs = timeframe_to_seconds(self.strategy.timeframe)
|
||||||
|
self._exit_reason_cache = PeriodicCache(100, ttl=timeframe_secs)
|
||||||
LoggingMixin.__init__(self, logger, timeframe_secs)
|
LoggingMixin.__init__(self, logger, timeframe_secs)
|
||||||
|
|
||||||
self._schedule = Scheduler()
|
self._schedule = Scheduler()
|
||||||
@@ -1374,6 +1375,14 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
for should_exit in exits:
|
for should_exit in exits:
|
||||||
if should_exit.exit_flag:
|
if should_exit.exit_flag:
|
||||||
exit_tag1 = exit_tag if should_exit.exit_type == ExitType.EXIT_SIGNAL else None
|
exit_tag1 = exit_tag if should_exit.exit_type == ExitType.EXIT_SIGNAL else None
|
||||||
|
if trade.has_open_orders:
|
||||||
|
pc = self._exit_reason_cache.get(
|
||||||
|
f"{trade.pair}_{trade.id}_{exit_tag1 or should_exit.exit_reason}", None
|
||||||
|
)
|
||||||
|
if pc:
|
||||||
|
logger.debug(f"Exit reason already seen this candle, first seen at {pc}")
|
||||||
|
continue
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Exit for {trade.pair} detected. Reason: {should_exit.exit_type}"
|
f"Exit for {trade.pair} detected. Reason: {should_exit.exit_type}"
|
||||||
f"{f' Tag: {exit_tag1}' if exit_tag1 is not None else ''}"
|
f"{f' Tag: {exit_tag1}' if exit_tag1 is not None else ''}"
|
||||||
@@ -2092,6 +2101,7 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
self.handle_insufficient_funds(trade)
|
self.handle_insufficient_funds(trade)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
self._exit_reason_cache[f"{trade.pair}_{trade.id}_{exit_reason}"] = dt_now()
|
||||||
order_obj = Order.parse_from_ccxt_object(order, trade.pair, trade.exit_side, amount, limit)
|
order_obj = Order.parse_from_ccxt_object(order, trade.pair, trade.exit_side, amount, limit)
|
||||||
order_obj.ft_order_tag = exit_reason
|
order_obj.ft_order_tag = exit_reason
|
||||||
trade.orders.append(order_obj)
|
trade.orders.append(order_obj)
|
||||||
|
|||||||
Reference in New Issue
Block a user