Update data downloading to include funding_fee downloads

This commit is contained in:
Matthias 2021-12-18 15:32:02 +01:00
parent 17bd990053
commit ddce28c12d
3 changed files with 19 additions and 18 deletions

View File

@ -283,17 +283,20 @@ def refresh_backtest_ohlcv_data(exchange: Exchange, pairs: List[str], timeframes
# Predefined candletype (and timeframe) depending on exchange # Predefined candletype (and timeframe) depending on exchange
# Downloads what is necessary to backtest based on futures data. # Downloads what is necessary to backtest based on futures data.
timeframe = exchange._ft_has['mark_ohlcv_timeframe'] timeframe = exchange._ft_has['mark_ohlcv_timeframe']
candle_type = CandleType.from_string(exchange._ft_has['mark_ohlcv_price']) fr_candle_type = CandleType.from_string(exchange._ft_has['mark_ohlcv_price'])
# All exchanges need FundingRate for futures trading.
# TODO: this could be in most parts to the above. # The timeframe is aligned to the mark-price timeframe.
if erase: for candle_type in (CandleType.FUNDING_RATE, fr_candle_type):
if data_handler.ohlcv_purge(pair, timeframe, candle_type=candle_type): # TODO: this could be in most parts to the above.
logger.info(f'Deleting existing data for pair {pair}, interval {timeframe}.') if erase:
_download_pair_history(pair=pair, process=process, if data_handler.ohlcv_purge(pair, timeframe, candle_type=candle_type):
datadir=datadir, exchange=exchange, logger.info(
timerange=timerange, data_handler=data_handler, f'Deleting existing data for pair {pair}, interval {timeframe}.')
timeframe=str(timeframe), new_pairs_days=new_pairs_days, _download_pair_history(pair=pair, process=process,
candle_type=candle_type) datadir=datadir, exchange=exchange,
timerange=timerange, data_handler=data_handler,
timeframe=str(timeframe), new_pairs_days=new_pairs_days,
candle_type=candle_type)
return pairs_not_available return pairs_not_available

View File

@ -1840,8 +1840,8 @@ class Exchange:
if self.funding_fee_cutoff(open_date): if self.funding_fee_cutoff(open_date):
open_date += timedelta(hours=1) open_date += timedelta(hours=1)
timeframe = self._ft_has['mark_ohlcv_timeframe']
open_date = timeframe_to_prev_date('1h', open_date) open_date = timeframe_to_prev_date(timeframe, open_date)
fees: float = 0 fees: float = 0
if not close_date: if not close_date:
@ -1850,11 +1850,9 @@ class Exchange:
# close_timestamp = int(close_date.timestamp()) * 1000 # close_timestamp = int(close_date.timestamp()) * 1000
mark_comb: PairWithTimeframe = ( mark_comb: PairWithTimeframe = (
pair, '1h', CandleType.from_string(self._ft_has["mark_ohlcv_price"])) pair, timeframe, CandleType.from_string(self._ft_has["mark_ohlcv_price"]))
# TODO-lev: 1h seems arbitrary and generates a lot of "empty" lines funding_comb: PairWithTimeframe = (pair, timeframe, CandleType.FUNDING_RATE)
# TODO-lev: probably a exchange-adjusted parameter would make more sense
funding_comb: PairWithTimeframe = (pair, '1h', CandleType.FUNDING_RATE)
candle_histories = self.refresh_latest_ohlcv( candle_histories = self.refresh_latest_ohlcv(
[mark_comb, funding_comb], [mark_comb, funding_comb],
since_ms=open_timestamp, since_ms=open_timestamp,

View File

@ -490,7 +490,7 @@ def test_validate_backtest_data(default_conf, mocker, caplog, testdatadir) -> No
@pytest.mark.parametrize('trademode,callcount', [ @pytest.mark.parametrize('trademode,callcount', [
('spot', 4), ('spot', 4),
('margin', 4), ('margin', 4),
('futures', 6), ('futures', 8), # Called 8 times - 4 normal, 2 funding and 2 mark/index calls
]) ])
def test_refresh_backtest_ohlcv_data( def test_refresh_backtest_ohlcv_data(
mocker, default_conf, markets, caplog, testdatadir, trademode, callcount): mocker, default_conf, markets, caplog, testdatadir, trademode, callcount):