Move download of live data to load_data
Avoids code duplication in backtesting and plot_dataframe
This commit is contained in:
parent
6451feee0e
commit
c2f6897d8b
@ -122,21 +122,29 @@ def load_data(datadir: Optional[Path],
|
|||||||
refresh_pairs: bool = False,
|
refresh_pairs: bool = False,
|
||||||
exchange: Optional[Exchange] = None,
|
exchange: Optional[Exchange] = None,
|
||||||
timerange: TimeRange = TimeRange(None, None, 0, 0),
|
timerange: TimeRange = TimeRange(None, None, 0, 0),
|
||||||
fill_up_missing: bool = True) -> Dict[str, DataFrame]:
|
fill_up_missing: bool = True,
|
||||||
|
live: bool = False
|
||||||
|
) -> Dict[str, DataFrame]:
|
||||||
"""
|
"""
|
||||||
Loads ticker history data for a list of pairs the given parameters
|
Loads ticker history data for a list of pairs the given parameters
|
||||||
:return: dict(<pair>:<tickerlist>)
|
:return: dict(<pair>:<tickerlist>)
|
||||||
"""
|
"""
|
||||||
result = {}
|
result = {}
|
||||||
|
if live:
|
||||||
|
logger.info('Live: Downloading data for all defined pairs ...')
|
||||||
|
exchange.refresh_latest_ohlcv([(pair, ticker_interval) for pair in pairs])
|
||||||
|
result = {key[0]: value for key, value in exchange._klines.items() if value is not None}
|
||||||
|
else:
|
||||||
|
logger.info('Using local backtesting data ...')
|
||||||
|
|
||||||
for pair in pairs:
|
for pair in pairs:
|
||||||
hist = load_pair_history(pair=pair, ticker_interval=ticker_interval,
|
hist = load_pair_history(pair=pair, ticker_interval=ticker_interval,
|
||||||
datadir=datadir, timerange=timerange,
|
datadir=datadir, timerange=timerange,
|
||||||
refresh_pairs=refresh_pairs,
|
refresh_pairs=refresh_pairs,
|
||||||
exchange=exchange,
|
exchange=exchange,
|
||||||
fill_up_missing=fill_up_missing)
|
fill_up_missing=fill_up_missing)
|
||||||
if hist is not None:
|
if hist is not None:
|
||||||
result[pair] = hist
|
result[pair] = hist
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
@ -401,24 +401,17 @@ class Backtesting(object):
|
|||||||
logger.info('Using stake_currency: %s ...', self.config['stake_currency'])
|
logger.info('Using stake_currency: %s ...', self.config['stake_currency'])
|
||||||
logger.info('Using stake_amount: %s ...', self.config['stake_amount'])
|
logger.info('Using stake_amount: %s ...', self.config['stake_amount'])
|
||||||
|
|
||||||
if self.config.get('live'):
|
timerange = Arguments.parse_timerange(None if self.config.get(
|
||||||
logger.info('Downloading data for all pairs in whitelist ...')
|
'timerange') is None else str(self.config.get('timerange')))
|
||||||
self.exchange.refresh_latest_ohlcv([(pair, self.ticker_interval) for pair in pairs])
|
data = history.load_data(
|
||||||
data = {key[0]: value for key, value in self.exchange._klines.items()}
|
datadir=Path(self.config['datadir']) if self.config.get('datadir') else None,
|
||||||
|
pairs=pairs,
|
||||||
else:
|
ticker_interval=self.ticker_interval,
|
||||||
logger.info('Using local backtesting data (using whitelist in given config) ...')
|
refresh_pairs=self.config.get('refresh_pairs', False),
|
||||||
|
exchange=self.exchange,
|
||||||
timerange = Arguments.parse_timerange(None if self.config.get(
|
timerange=timerange,
|
||||||
'timerange') is None else str(self.config.get('timerange')))
|
live=self.config.get('live', False)
|
||||||
data = history.load_data(
|
)
|
||||||
datadir=Path(self.config['datadir']) if self.config.get('datadir') else None,
|
|
||||||
pairs=pairs,
|
|
||||||
ticker_interval=self.ticker_interval,
|
|
||||||
refresh_pairs=self.config.get('refresh_pairs', False),
|
|
||||||
exchange=self.exchange,
|
|
||||||
timerange=timerange
|
|
||||||
)
|
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
logger.critical("No data found. Terminating.")
|
logger.critical("No data found. Terminating.")
|
||||||
|
Loading…
Reference in New Issue
Block a user