mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
Add helper method to calculate protection until
This commit is contained in:
parent
47cd856fea
commit
59091ef2b7
|
@ -182,6 +182,7 @@ class FreqtradeBot:
|
||||||
|
|
||||||
# Evaluate if protections should apply
|
# Evaluate if protections should apply
|
||||||
self.protections.global_stop()
|
self.protections.global_stop()
|
||||||
|
|
||||||
# Then looking for buy opportunities
|
# Then looking for buy opportunities
|
||||||
if self.get_free_open_trades():
|
if self.get_free_open_trades():
|
||||||
self.enter_positions()
|
self.enter_positions()
|
||||||
|
@ -1416,6 +1417,8 @@ class FreqtradeBot:
|
||||||
# Updating wallets when order is closed
|
# Updating wallets when order is closed
|
||||||
if not trade.is_open:
|
if not trade.is_open:
|
||||||
self.protections.stop_per_pair(trade.pair)
|
self.protections.stop_per_pair(trade.pair)
|
||||||
|
# Evaluate if protections should apply
|
||||||
|
# self.protections.global_stop()
|
||||||
self.wallets.update()
|
self.wallets.update()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,7 @@ class ProtectionManager():
|
||||||
|
|
||||||
# Early stopping - first positive result blocks further trades
|
# Early stopping - first positive result blocks further trades
|
||||||
if result and until:
|
if result and until:
|
||||||
|
if not PairLocks.is_global_lock(until):
|
||||||
PairLocks.lock_pair('*', until, reason)
|
PairLocks.lock_pair('*', until, reason)
|
||||||
result = True
|
result = True
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -42,8 +42,8 @@ class CooldownPeriod(IProtection):
|
||||||
trade = Trade.get_trades(filters).first()
|
trade = Trade.get_trades(filters).first()
|
||||||
if trade:
|
if trade:
|
||||||
self.log_on_refresh(logger.info, f"Cooldown for {pair} for {self._stop_duration}.")
|
self.log_on_refresh(logger.info, f"Cooldown for {pair} for {self._stop_duration}.")
|
||||||
until = trade.close_date.replace(
|
until = self.calculate_lock_end([trade], self._stop_duration)
|
||||||
tzinfo=timezone.utc) + timedelta(minutes=self._stop_duration)
|
|
||||||
return True, until, self._reason()
|
return True, until, self._reason()
|
||||||
|
|
||||||
return False, None, None
|
return False, None, None
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta, timezone
|
||||||
from typing import Any, Dict, Optional, Tuple
|
from typing import Any, Dict, List, Optional, Tuple
|
||||||
|
|
||||||
from freqtrade.mixins import LoggingMixin
|
from freqtrade.mixins import LoggingMixin
|
||||||
|
from freqtrade.persistence import Trade
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -45,3 +46,17 @@ class IProtection(LoggingMixin, ABC):
|
||||||
:return: Tuple of [bool, until, reason].
|
:return: Tuple of [bool, until, reason].
|
||||||
If true, this pair will be locked with <reason> until <until>
|
If true, this pair will be locked with <reason> until <until>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def calculate_lock_end(trades: List[Trade], stop_minutes: int) -> datetime:
|
||||||
|
"""
|
||||||
|
Get lock end time
|
||||||
|
"""
|
||||||
|
max_date: datetime = max([trade.close_date for trade in trades])
|
||||||
|
# comming from Database, tzinfo is not set.
|
||||||
|
if max_date.tzinfo is None:
|
||||||
|
max_date = max_date.replace(tzinfo=timezone.utc)
|
||||||
|
|
||||||
|
until = max_date + timedelta(minutes=stop_minutes)
|
||||||
|
|
||||||
|
return until
|
||||||
|
|
|
@ -3,7 +3,6 @@ import logging
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Any, Dict
|
from typing import Any, Dict
|
||||||
|
|
||||||
|
|
||||||
from freqtrade.persistence import Trade
|
from freqtrade.persistence import Trade
|
||||||
from freqtrade.plugins.protections import IProtection, ProtectionReturn
|
from freqtrade.plugins.protections import IProtection, ProtectionReturn
|
||||||
|
|
||||||
|
@ -57,7 +56,8 @@ class LowProfitPairs(IProtection):
|
||||||
logger.info,
|
logger.info,
|
||||||
f"Trading for {pair} stopped due to {profit} < {self._required_profit} "
|
f"Trading for {pair} stopped due to {profit} < {self._required_profit} "
|
||||||
f"within {self._lookback_period} minutes.")
|
f"within {self._lookback_period} minutes.")
|
||||||
until = date_now + timedelta(minutes=self._stop_duration)
|
until = self.calculate_lock_end(trades, self._stop_duration)
|
||||||
|
|
||||||
return True, until, self._reason(profit)
|
return True, until, self._reason(profit)
|
||||||
|
|
||||||
return False, None, None
|
return False, None, None
|
||||||
|
|
|
@ -55,7 +55,7 @@ class StoplossGuard(IProtection):
|
||||||
if len(trades) > self._trade_limit:
|
if len(trades) > self._trade_limit:
|
||||||
self.log_on_refresh(logger.info, f"Trading stopped due to {self._trade_limit} "
|
self.log_on_refresh(logger.info, f"Trading stopped due to {self._trade_limit} "
|
||||||
f"stoplosses within {self._lookback_period} minutes.")
|
f"stoplosses within {self._lookback_period} minutes.")
|
||||||
until = date_now + timedelta(minutes=self._stop_duration)
|
until = self.calculate_lock_end(trades, self._stop_duration)
|
||||||
return True, until, self._reason()
|
return True, until, self._reason()
|
||||||
|
|
||||||
return False, None, None
|
return False, None, None
|
||||||
|
|
Loading…
Reference in New Issue
Block a user