From 0ea8957cccc97a975960abe20ad089ffa56a3bc2 Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Fri, 29 Oct 2021 20:07:24 -0600 Subject: [PATCH] removed ftx get_mark_price_history, added variable mark_ohlcv_price, used fetch_ohlcv instead of fetch_mark_ohlcv inside get_mark_price_history --- freqtrade/exchange/exchange.py | 40 ++++++++++++++++++++++++---------- freqtrade/exchange/ftx.py | 30 ++----------------------- 2 files changed, 31 insertions(+), 39 deletions(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 3069aea61..ed21e57b9 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -80,6 +80,8 @@ class Exchange: # TradingMode.SPOT always supported and not required in this list ] + mark_ohlcv_price = 'mark' + def __init__(self, config: Dict[str, Any], validate: bool = True) -> None: """ Initializes this module with the given config, @@ -1744,15 +1746,32 @@ class Exchange: Get's the mark price history for a pair """ - candles = self._api.fetch_mark_ohlcv( - pair, - timeframe="1h", - since=start - ) - history = {} - for candle in candles: - history[candle[0]] = candle[1] - return history + try: + candles = self._api.fetch_ohlcv( + pair, + timeframe="1h", + since=start, + params={ + 'price': self.mark_ohlcv_price + } + ) + history = {} + for candle in candles: + history[candle[0]] = candle[1] + return history + except ccxt.NotSupported as e: + raise OperationalException( + f'Exchange {self._api.name} does not support fetching historical ' + f'mark price candle (OHLCV) data. Message: {e}') from e + except ccxt.DDoSProtection as e: + raise DDosProtection(e) from e + except (ccxt.NetworkError, ccxt.ExchangeError) as e: + raise TemporaryError(f'Could not fetch historical mark price candle (OHLCV) data ' + f'for pair {pair} due to {e.__class__.__name__}. ' + f'Message: {e}') from e + except ccxt.BaseError as e: + raise OperationalException(f'Could not fetch historical mark price candle (OHLCV) data ' + f'for pair {pair}. Message: {e}') from e def calculate_funding_fees( self, @@ -1779,8 +1798,7 @@ class Exchange: ) mark_price_history = self._get_mark_price_history( pair, - int(open_date.timestamp()), - close_date_timestamp + int(open_date.timestamp()) ) for date in self._get_funding_fee_dates(open_date, close_date): funding_rate = funding_rate_history[date.timestamp] diff --git a/freqtrade/exchange/ftx.py b/freqtrade/exchange/ftx.py index e78c43872..14045e302 100644 --- a/freqtrade/exchange/ftx.py +++ b/freqtrade/exchange/ftx.py @@ -1,6 +1,6 @@ """ FTX exchange subclass """ import logging -from typing import Any, Dict, List, Optional, Tuple +from typing import Any, Dict, List, Tuple import ccxt @@ -28,6 +28,7 @@ class Ftx(Exchange): # (TradingMode.MARGIN, Collateral.CROSS), # TODO-lev: Uncomment once supported # (TradingMode.FUTURES, Collateral.CROSS) # TODO-lev: Uncomment once supported ] + mark_ohlcv_price = 'index' def market_is_tradable(self, market: Dict[str, Any]) -> bool: """ @@ -168,30 +169,3 @@ class Ftx(Exchange): if order['type'] == 'stop': return safe_value_fallback2(order, order, 'id_stop', 'id') return order['id'] - - def _get_mark_price_history( - self, - pair: str, - start: int, - end: Optional[int] - ) -> Dict: - """ - Get's the mark price history for a pair - """ - if end: - params = { - 'endTime': end - } - else: - params = {} - - candles = self._api.fetch_index_ohlcv( - pair, - timeframe="1h", - since=start, - params=params - ) - history = {} - for candle in candles: - history[candle[0]] = candle[1] - return history