Simplify downloading futures data code
This commit is contained in:
parent
95f69a8c3b
commit
cd2e49bb60
@ -179,6 +179,7 @@ def _download_pair_history(pair: str, *,
|
|||||||
data_handler: IDataHandler = None,
|
data_handler: IDataHandler = None,
|
||||||
timerange: Optional[TimeRange] = None,
|
timerange: Optional[TimeRange] = None,
|
||||||
candle_type: CandleType,
|
candle_type: CandleType,
|
||||||
|
erase: bool = False,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""
|
"""
|
||||||
Download latest candles from the exchange for the pair and timeframe passed in parameters
|
Download latest candles from the exchange for the pair and timeframe passed in parameters
|
||||||
@ -192,11 +193,16 @@ def _download_pair_history(pair: str, *,
|
|||||||
:param timeframe: Timeframe (e.g "5m")
|
:param timeframe: Timeframe (e.g "5m")
|
||||||
:param timerange: range of time to download
|
:param timerange: range of time to download
|
||||||
:param candle_type: Any of the enum CandleType (must match trading mode!)
|
:param candle_type: Any of the enum CandleType (must match trading mode!)
|
||||||
|
:param erase: Erase existing data
|
||||||
:return: bool with success state
|
:return: bool with success state
|
||||||
"""
|
"""
|
||||||
data_handler = get_datahandler(datadir, data_handler=data_handler)
|
data_handler = get_datahandler(datadir, data_handler=data_handler)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if erase:
|
||||||
|
if data_handler.ohlcv_purge(pair, timeframe, candle_type=candle_type):
|
||||||
|
logger.info(f'Deleting existing data for pair {pair}, {timeframe}, {candle_type}.')
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f'Download history data for pair: "{pair}" ({process}), timeframe: {timeframe}, '
|
f'Download history data for pair: "{pair}" ({process}), timeframe: {timeframe}, '
|
||||||
f'candle type: {candle_type} and store in {datadir}.'
|
f'candle type: {candle_type} and store in {datadir}.'
|
||||||
@ -267,35 +273,28 @@ def refresh_backtest_ohlcv_data(exchange: Exchange, pairs: List[str], timeframes
|
|||||||
continue
|
continue
|
||||||
for timeframe in timeframes:
|
for timeframe in timeframes:
|
||||||
|
|
||||||
if erase:
|
|
||||||
if data_handler.ohlcv_purge(pair, timeframe, candle_type=candle_type):
|
|
||||||
logger.info(f'Deleting existing data for pair {pair}, interval {timeframe}.')
|
|
||||||
|
|
||||||
logger.info(f'Downloading pair {pair}, interval {timeframe}.')
|
logger.info(f'Downloading pair {pair}, interval {timeframe}.')
|
||||||
process = f'{idx}/{len(pairs)}'
|
process = f'{idx}/{len(pairs)}'
|
||||||
_download_pair_history(pair=pair, process=process,
|
_download_pair_history(pair=pair, process=process,
|
||||||
datadir=datadir, exchange=exchange,
|
datadir=datadir, exchange=exchange,
|
||||||
timerange=timerange, data_handler=data_handler,
|
timerange=timerange, data_handler=data_handler,
|
||||||
timeframe=str(timeframe), new_pairs_days=new_pairs_days,
|
timeframe=str(timeframe), new_pairs_days=new_pairs_days,
|
||||||
candle_type=candle_type)
|
candle_type=candle_type,
|
||||||
|
erase=erase)
|
||||||
if trading_mode == 'futures':
|
if trading_mode == 'futures':
|
||||||
# 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']
|
tf_mark = exchange._ft_has['mark_ohlcv_timeframe']
|
||||||
fr_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.
|
# All exchanges need FundingRate for futures trading.
|
||||||
# The timeframe is aligned to the mark-price timeframe.
|
# The timeframe is aligned to the mark-price timeframe.
|
||||||
for funding_candle_type in (CandleType.FUNDING_RATE, fr_candle_type):
|
for funding_candle_type in (CandleType.FUNDING_RATE, fr_candle_type):
|
||||||
# TODO: this could be in most parts to the above.
|
|
||||||
if erase:
|
|
||||||
if data_handler.ohlcv_purge(pair, timeframe, candle_type=funding_candle_type):
|
|
||||||
logger.info(
|
|
||||||
f'Deleting existing data for pair {pair}, interval {timeframe}.')
|
|
||||||
_download_pair_history(pair=pair, process=process,
|
_download_pair_history(pair=pair, process=process,
|
||||||
datadir=datadir, exchange=exchange,
|
datadir=datadir, exchange=exchange,
|
||||||
timerange=timerange, data_handler=data_handler,
|
timerange=timerange, data_handler=data_handler,
|
||||||
timeframe=str(timeframe), new_pairs_days=new_pairs_days,
|
timeframe=str(tf_mark), new_pairs_days=new_pairs_days,
|
||||||
candle_type=funding_candle_type)
|
candle_type=funding_candle_type,
|
||||||
|
erase=erase)
|
||||||
|
|
||||||
return pairs_not_available
|
return pairs_not_available
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user