allow only loading 1 pair if necessary
* simplify tests nad remove unnecessary mocking
This commit is contained in:
parent
429f846ad1
commit
8a3c2a0c63
@ -95,6 +95,31 @@ def load_tickerdata_file(
|
|||||||
return pairdata
|
return pairdata
|
||||||
|
|
||||||
|
|
||||||
|
def load_pair_history(pair: str,
|
||||||
|
ticker_interval: str,
|
||||||
|
datadir: Optional[Path],
|
||||||
|
timerange: TimeRange = TimeRange(None, None, 0, 0)) -> DataFrame:
|
||||||
|
"""
|
||||||
|
Loads cached ticker history for the given pair.
|
||||||
|
"""
|
||||||
|
|
||||||
|
pairdata = load_tickerdata_file(datadir, pair, ticker_interval, timerange=timerange)
|
||||||
|
if pairdata:
|
||||||
|
if timerange.starttype == 'date' and pairdata[0][0] > timerange.startts * 1000:
|
||||||
|
logger.warning('Missing data at start for pair %s, data starts at %s',
|
||||||
|
pair, arrow.get(pairdata[0][0] // 1000).strftime('%Y-%m-%d %H:%M:%S'))
|
||||||
|
if timerange.stoptype == 'date' and pairdata[-1][0] < timerange.stopts * 1000:
|
||||||
|
logger.warning('Missing data at end for pair %s, data ends at %s',
|
||||||
|
pair,
|
||||||
|
arrow.get(pairdata[-1][0] // 1000).strftime('%Y-%m-%d %H:%M:%S'))
|
||||||
|
return parse_ticker_dataframe(pairdata)
|
||||||
|
else:
|
||||||
|
logger.warning('No data for pair: "%s", Interval: %s. '
|
||||||
|
'Use --refresh-pairs-cached to download the data',
|
||||||
|
pair, ticker_interval)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def load_data(datadir: Optional[Path],
|
def load_data(datadir: Optional[Path],
|
||||||
ticker_interval: str,
|
ticker_interval: str,
|
||||||
pairs: List[str],
|
pairs: List[str],
|
||||||
@ -116,22 +141,10 @@ def load_data(datadir: Optional[Path],
|
|||||||
download_pairs(datadir, exchange, pairs, ticker_interval, timerange=timerange)
|
download_pairs(datadir, exchange, pairs, ticker_interval, timerange=timerange)
|
||||||
|
|
||||||
for pair in pairs:
|
for pair in pairs:
|
||||||
pairdata = load_tickerdata_file(datadir, pair, ticker_interval, timerange=timerange)
|
hist = load_pair_history(pair=pair, ticker_interval=ticker_interval,
|
||||||
if pairdata:
|
datadir=datadir, timerange=timerange)
|
||||||
if timerange.starttype == 'date' and pairdata[0][0] > timerange.startts * 1000:
|
if hist is not None:
|
||||||
logger.warning('Missing data at start for pair %s, data starts at %s',
|
result[pair] = hist
|
||||||
pair,
|
|
||||||
arrow.get(pairdata[0][0] // 1000).strftime('%Y-%m-%d %H:%M:%S'))
|
|
||||||
if timerange.stoptype == 'date' and pairdata[-1][0] < timerange.stopts * 1000:
|
|
||||||
logger.warning('Missing data at end for pair %s, data ends at %s',
|
|
||||||
pair,
|
|
||||||
arrow.get(pairdata[-1][0] // 1000).strftime('%Y-%m-%d %H:%M:%S'))
|
|
||||||
result[pair] = parse_ticker_dataframe(pairdata)
|
|
||||||
else:
|
|
||||||
logger.warning('No data for pair: "%s", Interval: %s. '
|
|
||||||
'Use --refresh-pairs-cached to download the data',
|
|
||||||
pair, ticker_interval)
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import uuid
|
|||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
|
|
||||||
import arrow
|
import arrow
|
||||||
|
from pandas import DataFrame
|
||||||
|
|
||||||
from freqtrade.arguments import TimeRange
|
from freqtrade.arguments import TimeRange
|
||||||
from freqtrade.data import history
|
from freqtrade.data import history
|
||||||
@ -54,26 +55,19 @@ def _clean_test_file(file: str) -> None:
|
|||||||
os.rename(file_swp, file)
|
os.rename(file_swp, file)
|
||||||
|
|
||||||
|
|
||||||
def test_load_data_30min_ticker(ticker_history, mocker, caplog, default_conf) -> None:
|
def test_load_data_30min_ticker(mocker, caplog, default_conf) -> None:
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_history', return_value=ticker_history)
|
ld = history.load_pair_history(pair='UNITTEST/BTC', ticker_interval='30m', datadir=None)
|
||||||
file = os.path.join(os.path.dirname(__file__), '..', 'testdata', 'UNITTEST_BTC-30m.json')
|
assert isinstance(ld, DataFrame)
|
||||||
_backup_file(file, copy_file=True)
|
|
||||||
ld = history.load_data(datadir=None, pairs=['UNITTEST/BTC'], ticker_interval='30m')
|
|
||||||
assert isinstance(ld, dict)
|
|
||||||
assert os.path.isfile(file) is True
|
|
||||||
assert not log_has('Download the pair: "UNITTEST/BTC", Interval: 30m', caplog.record_tuples)
|
assert not log_has('Download the pair: "UNITTEST/BTC", Interval: 30m', caplog.record_tuples)
|
||||||
_clean_test_file(file)
|
|
||||||
|
|
||||||
|
|
||||||
def test_load_data_5min_ticker(ticker_history, mocker, caplog, default_conf) -> None:
|
def test_load_data_7min_ticker(mocker, caplog, default_conf) -> None:
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_history', return_value=ticker_history)
|
ld = history.load_pair_history(pair='UNITTEST/BTC', ticker_interval='7m', datadir=None)
|
||||||
|
assert not isinstance(ld, DataFrame)
|
||||||
file = os.path.join(os.path.dirname(__file__), '..', 'testdata', 'UNITTEST_BTC-5m.json')
|
assert ld is None
|
||||||
_backup_file(file, copy_file=True)
|
assert log_has(
|
||||||
history.load_data(datadir=None, pairs=['UNITTEST/BTC'], ticker_interval='5m')
|
'No data for pair: "UNITTEST/BTC", Interval: 7m. '
|
||||||
assert os.path.isfile(file) is True
|
'Use --refresh-pairs-cached to download the data', caplog.record_tuples)
|
||||||
assert not log_has('Download the pair: "UNITTEST/BTC", Interval: 5m', caplog.record_tuples)
|
|
||||||
_clean_test_file(file)
|
|
||||||
|
|
||||||
|
|
||||||
def test_load_data_1min_ticker(ticker_history, mocker, caplog) -> None:
|
def test_load_data_1min_ticker(ticker_history, mocker, caplog) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user