From c333c9c5a1bf36b50520732acc3eee43467c3c75 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 21 Jan 2024 14:08:35 +0100 Subject: [PATCH] Improve kraken trades pagination logic --- freqtrade/exchange/exchange.py | 9 ++++++++- freqtrade/exchange/kraken.py | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 664000eb2..111aac681 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -2250,6 +2250,13 @@ class Exchange: except ccxt.BaseError as e: raise OperationalException(f'Could not fetch trade data. Msg: {e}') from e + def _valid_trade_pagination_id(self, pair: str, from_id: str) -> bool: + """ + Verify trade-pagination id is valid. + Workaround for odd Kraken issue where ID is sometimes wrong. + """ + return True + async def _async_get_trade_history_id(self, pair: str, until: int, since: Optional[int] = None, @@ -2266,7 +2273,7 @@ class Exchange: trades: List[List] = [] - if not from_id: + if not from_id or not self._valid_trade_pagination_id(pair, from_id): # Fetch first elements using timebased method to get an ID to paginate on # Depending on the Exchange, this can introduce a drift at the start of the interval # of up to an hour. diff --git a/freqtrade/exchange/kraken.py b/freqtrade/exchange/kraken.py index a84a48d80..e49b7fd54 100644 --- a/freqtrade/exchange/kraken.py +++ b/freqtrade/exchange/kraken.py @@ -172,3 +172,15 @@ class Kraken(Exchange): trades[-1]['id'] = trades[-1].get('info', [])[-1] return trades + + def _valid_trade_pagination_id(self, pair: str, from_id: str) -> bool: + """ + Verify trade-pagination id is valid. + Workaround for odd Kraken issue where ID is sometimes wrong. + """ + # Regular id's are in timestamp format 1705443695120072285 + # If the id is smaller than 19 characters, it's not a valid timestamp. + if len(from_id) >= 19: + return True + logger.debug("trade-pagination id is not valid. Fallback to timestamp.") + return False