Improve kraken trades pagination logic
This commit is contained in:
@@ -2250,6 +2250,13 @@ class Exchange:
|
|||||||
except ccxt.BaseError as e:
|
except ccxt.BaseError as e:
|
||||||
raise OperationalException(f'Could not fetch trade data. Msg: {e}') from 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,
|
async def _async_get_trade_history_id(self, pair: str,
|
||||||
until: int,
|
until: int,
|
||||||
since: Optional[int] = None,
|
since: Optional[int] = None,
|
||||||
@@ -2266,7 +2273,7 @@ class Exchange:
|
|||||||
|
|
||||||
trades: List[List] = []
|
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
|
# 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
|
# Depending on the Exchange, this can introduce a drift at the start of the interval
|
||||||
# of up to an hour.
|
# of up to an hour.
|
||||||
|
|||||||
@@ -172,3 +172,15 @@ class Kraken(Exchange):
|
|||||||
|
|
||||||
trades[-1]['id'] = trades[-1].get('info', [])[-1]
|
trades[-1]['id'] = trades[-1].get('info', [])[-1]
|
||||||
return trades
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user