From 798438df9df6820bfc86f1547ad6d20cadad84fe Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 30 Dec 2022 07:32:59 +0100 Subject: [PATCH] Extract funding-rate call to separate method this will allow overwriting in subclasses. --- freqtrade/exchange/exchange.py | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 381f366fd..51341588d 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -2050,11 +2050,12 @@ class Exchange: limit=candle_limit, params=params) else: # Funding rate - data = await self._api_async.fetch_funding_rate_history( - pair, since=since_ms, - limit=candle_limit) - # Convert funding rate to candle pattern - data = [[x['timestamp'], x['fundingRate'], 0, 0, 0, 0] for x in data] + data = await self._fetch_funding_rate_history( + pair=pair, + timeframe=timeframe, + limit=candle_limit, + since_ms=since_ms, + ) # Some exchanges sort OHLCV in ASC order and others in DESC. # Ex: Bittrex returns the list of OHLCV in ASC order (oldest first, newest last) # while GDAX returns the list of OHLCV in DESC order (newest first, oldest last) @@ -2082,6 +2083,24 @@ class Exchange: raise OperationalException(f'Could not fetch historical candle (OHLCV) data ' f'for pair {pair}. Message: {e}') from e + async def _fetch_funding_rate_history( + self, + pair: str, + timeframe: str, + limit: int, + since_ms: Optional[int] = None, + ) -> List[List]: + """ + Fetch funding rate history - used to selectively override this by subclasses. + """ + # Funding rate + data = await self._api_async.fetch_funding_rate_history( + pair, since=since_ms, + limit=limit) + # Convert funding rate to candle pattern + data = [[x['timestamp'], x['fundingRate'], 0, 0, 0, 0] for x in data] + return data + # Fetch historic trades @retrier_async