From 56b07386aece6455adb9a58d6f5fee28ad4391b8 Mon Sep 17 00:00:00 2001 From: Joe Schr <8218910+TheJoeSchr@users.noreply.github.com> Date: Wed, 8 May 2024 15:08:25 +0200 Subject: [PATCH] fix `_now_is_time_to_refresh_trades` so it checks for latest fetched trades --- freqtrade/exchange/exchange.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index bde382362..3058f5095 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -126,7 +126,6 @@ class Exchange: # Holds last candle refreshed time of each pair self._pairs_last_refresh_time: Dict[PairWithTimeframe, int] = {} - self._trades_last_refresh_time: Dict[PairWithTimeframe, int] = {} # Timestamp of last markets refresh self._last_markets_refresh: int = 0 @@ -2329,9 +2328,6 @@ class Exchange: # keeping last candle time as last refreshed time of the pair if ticks and cache: idx = -1 - # NOTE: // is floor: divides and rounds to nearest int - self._trades_last_refresh_time[ - (pair, timeframe, c_type)] = trades_df['timestamp'].iat[idx] // 1000 if cache: if (pair, timeframe, c_type) in self._trades: @@ -2448,17 +2444,15 @@ class Exchange: return results_df - def _now_is_time_to_refresh_trades(self, - pair: str, - timeframe: str, - candle_type: CandleType) -> bool: - # Timeframe in seconds - df = self.klines((pair, timeframe, candle_type), True) - _calculate_ohlcv_candle_start_and_end(df, timeframe) - timeframe_to_seconds(timeframe) - plr = round(df.iloc[-1]["candle_end"].timestamp()) - now = int(timeframe_to_prev_date(timeframe).timestamp()) - return plr < now + def _now_is_time_to_refresh_trades( + self, pair: str, timeframe: str, candle_type: CandleType + ) -> bool: # Timeframe in seconds + trades = self.trades((pair, timeframe, candle_type), False) + pair_last_refreshed = int(trades.iloc[-1]["timestamp"]) + full_candle = int(timeframe_to_next_date( + timeframe, dt_from_ts(pair_last_refreshed)).timestamp()) * 1000 + now = dt_ts() + return full_candle <= now # Fetch historic trades