Lock pair until a new candle arrives
This commit is contained in:
@@ -433,7 +433,9 @@ class FreqtradeBot:
|
||||
"""
|
||||
logger.debug(f"create_trade for pair {pair}")
|
||||
|
||||
if self.strategy.is_pair_locked(pair):
|
||||
analyzed_df, _ = self.dataprovider.get_analyzed_dataframe(pair, self.strategy.timeframe)
|
||||
if self.strategy.is_pair_locked(
|
||||
pair, analyzed_df.iloc[-1]['date'] if len(analyzed_df) > 0 else None):
|
||||
logger.info(f"Pair {pair} is currently locked.")
|
||||
return False
|
||||
|
||||
@@ -444,7 +446,6 @@ class FreqtradeBot:
|
||||
return False
|
||||
|
||||
# running get_signal on historical data fetched
|
||||
analyzed_df, _ = self.dataprovider.get_analyzed_dataframe(pair, self.strategy.timeframe)
|
||||
(buy, sell) = self.strategy.get_signal(pair, self.strategy.timeframe, analyzed_df)
|
||||
|
||||
if buy and not sell:
|
||||
|
@@ -2,6 +2,7 @@
|
||||
IStrategy interface
|
||||
This module defines the interface to apply for strategies
|
||||
"""
|
||||
from freqtrade.exchange.exchange import timeframe_to_next_date
|
||||
import logging
|
||||
import warnings
|
||||
from abc import ABC, abstractmethod
|
||||
@@ -297,13 +298,22 @@ class IStrategy(ABC):
|
||||
if pair in self._pair_locked_until:
|
||||
del self._pair_locked_until[pair]
|
||||
|
||||
def is_pair_locked(self, pair: str) -> bool:
|
||||
def is_pair_locked(self, pair: str, candle_date: datetime = None) -> bool:
|
||||
"""
|
||||
Checks if a pair is currently locked
|
||||
"""
|
||||
if pair not in self._pair_locked_until:
|
||||
return False
|
||||
return self._pair_locked_until[pair] >= datetime.now(timezone.utc)
|
||||
if not candle_date:
|
||||
return self._pair_locked_until[pair] >= datetime.now(timezone.utc)
|
||||
else:
|
||||
# Locking should happen until a new candle arrives
|
||||
lock_time = timeframe_to_next_date(self.timeframe, candle_date)
|
||||
# lock_time = candle_date + timedelta(minutes=timeframe_to_minutes(self.timeframe))
|
||||
res = self._pair_locked_until[pair] > lock_time
|
||||
logger.debug(f"pair time = {lock_time} - pair_lock = {self._pair_locked_until[pair]} "
|
||||
f"- res: {res}")
|
||||
return res
|
||||
|
||||
def analyze_ticker(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
"""
|
||||
@@ -438,12 +448,6 @@ class IStrategy(ABC):
|
||||
)
|
||||
return False, False
|
||||
|
||||
# Check if dataframe has new candle
|
||||
if (arrow.utcnow() - latest_date).total_seconds() // 60 >= timeframe_minutes:
|
||||
logger.warning('Old candle for pair %s. Last candle is %s minutes old',
|
||||
pair, int((arrow.utcnow() - latest_date).total_seconds() // 60))
|
||||
return False, False
|
||||
|
||||
(buy, sell) = latest[SignalType.BUY.value] == 1, latest[SignalType.SELL.value] == 1
|
||||
logger.debug('trigger: %s (pair=%s) buy=%s sell=%s',
|
||||
latest['date'], pair, str(buy), str(sell))
|
||||
|
Reference in New Issue
Block a user