allow reloading single pair
This commit is contained in:
parent
ebb80b6906
commit
043cefd60a
@ -99,12 +99,28 @@ def load_tickerdata_file(
|
|||||||
def load_pair_history(pair: str,
|
def load_pair_history(pair: str,
|
||||||
ticker_interval: str,
|
ticker_interval: str,
|
||||||
datadir: Optional[Path],
|
datadir: Optional[Path],
|
||||||
timerange: TimeRange = TimeRange(None, None, 0, 0)) -> DataFrame:
|
timerange: TimeRange = TimeRange(None, None, 0, 0),
|
||||||
|
refresh_pairs: bool = False,
|
||||||
|
exchange: Optional[Exchange] = None,
|
||||||
|
) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
Loads cached ticker history for the given pair.
|
Loads cached ticker history for the given pair.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pairdata = load_tickerdata_file(datadir, pair, ticker_interval, timerange=timerange)
|
pairdata = load_tickerdata_file(datadir, pair, ticker_interval, timerange=timerange)
|
||||||
|
# If the user force the refresh of pairs
|
||||||
|
if refresh_pairs:
|
||||||
|
if not exchange:
|
||||||
|
raise OperationalException("Exchange needs to be initialized when "
|
||||||
|
"calling load_data with refresh_pairs=True")
|
||||||
|
|
||||||
|
logger.info('Download data for all pairs and store them in %s', datadir)
|
||||||
|
download_backtesting_testdata(datadir=datadir,
|
||||||
|
exchange=exchange,
|
||||||
|
pair=pair,
|
||||||
|
tick_interval=ticker_interval,
|
||||||
|
timerange=timerange)
|
||||||
|
|
||||||
if pairdata:
|
if pairdata:
|
||||||
if timerange.starttype == 'date' and pairdata[0][0] > timerange.startts * 1000:
|
if timerange.starttype == 'date' and pairdata[0][0] > timerange.startts * 1000:
|
||||||
logger.warning('Missing data at start for pair %s, data starts at %s',
|
logger.warning('Missing data at start for pair %s, data starts at %s',
|
||||||
@ -124,26 +140,20 @@ def load_pair_history(pair: str,
|
|||||||
def load_data(datadir: Optional[Path],
|
def load_data(datadir: Optional[Path],
|
||||||
ticker_interval: str,
|
ticker_interval: str,
|
||||||
pairs: List[str],
|
pairs: List[str],
|
||||||
refresh_pairs: Optional[bool] = False,
|
refresh_pairs: bool = False,
|
||||||
exchange: Optional[Exchange] = None,
|
exchange: Optional[Exchange] = None,
|
||||||
timerange: TimeRange = TimeRange(None, None, 0, 0)) -> Dict[str, DataFrame]:
|
timerange: TimeRange = TimeRange(None, None, 0, 0)) -> Dict[str, DataFrame]:
|
||||||
"""
|
"""
|
||||||
Loads ticker history data for the given parameters
|
Loads ticker history data for a list of pairs the given parameters
|
||||||
:return: dict
|
:return: dict
|
||||||
"""
|
"""
|
||||||
result = {}
|
result = {}
|
||||||
|
|
||||||
# If the user force the refresh of pairs
|
|
||||||
if refresh_pairs:
|
|
||||||
logger.info('Download data for all pairs and store them in %s', datadir)
|
|
||||||
if not exchange:
|
|
||||||
raise OperationalException("Exchange needs to be initialized when "
|
|
||||||
"calling load_data with refresh_pairs=True")
|
|
||||||
download_pairs(datadir, exchange, pairs, ticker_interval, timerange=timerange)
|
|
||||||
|
|
||||||
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,
|
||||||
|
exchange=exchange)
|
||||||
if hist is not None:
|
if hist is not None:
|
||||||
result[pair] = hist
|
result[pair] = hist
|
||||||
return result
|
return result
|
||||||
@ -160,7 +170,7 @@ def download_pairs(datadir, exchange: Exchange, pairs: List[str],
|
|||||||
"""For each pairs passed in parameters, download the ticker intervals"""
|
"""For each pairs passed in parameters, download the ticker intervals"""
|
||||||
for pair in pairs:
|
for pair in pairs:
|
||||||
try:
|
try:
|
||||||
download_backtesting_testdata(datadir,
|
download_backtesting_testdata(datadir=datadir,
|
||||||
exchange=exchange,
|
exchange=exchange,
|
||||||
pair=pair,
|
pair=pair,
|
||||||
tick_interval=ticker_interval,
|
tick_interval=ticker_interval,
|
||||||
|
@ -8,7 +8,9 @@ from shutil import copyfile
|
|||||||
|
|
||||||
import arrow
|
import arrow
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from freqtrade import OperationalException
|
||||||
from freqtrade.arguments import TimeRange
|
from freqtrade.arguments import TimeRange
|
||||||
from freqtrade.data import history
|
from freqtrade.data import history
|
||||||
from freqtrade.data.history import (download_backtesting_testdata,
|
from freqtrade.data.history import (download_backtesting_testdata,
|
||||||
@ -82,7 +84,7 @@ def test_load_data_1min_ticker(ticker_history, mocker, caplog) -> None:
|
|||||||
|
|
||||||
def test_load_data_with_new_pair_1min(ticker_history_list, mocker, caplog, default_conf) -> None:
|
def test_load_data_with_new_pair_1min(ticker_history_list, mocker, caplog, default_conf) -> None:
|
||||||
"""
|
"""
|
||||||
Test load_data() with 1 min ticker
|
Test load_pair_history() with 1 min ticker
|
||||||
"""
|
"""
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_history', return_value=ticker_history_list)
|
mocker.patch('freqtrade.exchange.Exchange.get_history', return_value=ticker_history_list)
|
||||||
exchange = get_patched_exchange(mocker, default_conf)
|
exchange = get_patched_exchange(mocker, default_conf)
|
||||||
@ -90,23 +92,29 @@ def test_load_data_with_new_pair_1min(ticker_history_list, mocker, caplog, defau
|
|||||||
|
|
||||||
_backup_file(file)
|
_backup_file(file)
|
||||||
# do not download a new pair if refresh_pairs isn't set
|
# do not download a new pair if refresh_pairs isn't set
|
||||||
history.load_data(datadir=None,
|
history.load_pair_history(datadir=None,
|
||||||
ticker_interval='1m',
|
ticker_interval='1m',
|
||||||
refresh_pairs=False,
|
refresh_pairs=False,
|
||||||
pairs=['MEME/BTC'])
|
pair='MEME/BTC')
|
||||||
assert os.path.isfile(file) is False
|
assert os.path.isfile(file) is False
|
||||||
assert log_has('No data for pair: "MEME/BTC", Interval: 1m. '
|
assert log_has('No data for pair: "MEME/BTC", Interval: 1m. '
|
||||||
'Use --refresh-pairs-cached to download the data',
|
'Use --refresh-pairs-cached to download the data',
|
||||||
caplog.record_tuples)
|
caplog.record_tuples)
|
||||||
|
|
||||||
# download a new pair if refresh_pairs is set
|
# download a new pair if refresh_pairs is set
|
||||||
history.load_data(datadir=None,
|
history.load_pair_history(datadir=None,
|
||||||
ticker_interval='1m',
|
ticker_interval='1m',
|
||||||
refresh_pairs=True,
|
refresh_pairs=True,
|
||||||
exchange=exchange,
|
exchange=exchange,
|
||||||
pairs=['MEME/BTC'])
|
pair='MEME/BTC')
|
||||||
assert os.path.isfile(file) is True
|
assert os.path.isfile(file) is True
|
||||||
assert log_has('Download the pair: "MEME/BTC", Interval: 1m', caplog.record_tuples)
|
assert log_has('Download the pair: "MEME/BTC", Interval: 1m', caplog.record_tuples)
|
||||||
|
with pytest.raises(OperationalException, match=r'Exchange needs to be initialized when.*'):
|
||||||
|
history.load_pair_history(datadir=None,
|
||||||
|
ticker_interval='1m',
|
||||||
|
refresh_pairs=True,
|
||||||
|
exchange=None,
|
||||||
|
pair='MEME/BTC')
|
||||||
_clean_test_file(file)
|
_clean_test_file(file)
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ for pair in PAIRS:
|
|||||||
dl_file.unlink()
|
dl_file.unlink()
|
||||||
|
|
||||||
print(f'downloading pair {pair}, interval {tick_interval}')
|
print(f'downloading pair {pair}, interval {tick_interval}')
|
||||||
download_backtesting_testdata(dl_path, exchange=exchange,
|
download_backtesting_testdata(datadir=dl_path, exchange=exchange,
|
||||||
pair=pair,
|
pair=pair,
|
||||||
tick_interval=tick_interval,
|
tick_interval=tick_interval,
|
||||||
timerange=timerange)
|
timerange=timerange)
|
||||||
|
Loading…
Reference in New Issue
Block a user