Cleanup and tests for refresh_backtest_trades

This commit is contained in:
Matthias 2019-10-08 20:45:35 +02:00
parent 1b7a09c184
commit 2374cda8d0
2 changed files with 29 additions and 8 deletions

View File

@ -82,7 +82,7 @@ def store_tickerdata_file(datadir: Path, pair: str,
misc.file_dump_json(filename, data, is_zip=is_zip)
def load_trades_file(datadir: Optional[Path], pair: str,
def load_trades_file(datadir: Path, pair: str,
timerange: Optional[TimeRange] = None) -> List[Dict]:
"""
Load a pair from file, either .json.gz or .json
@ -97,7 +97,7 @@ def load_trades_file(datadir: Optional[Path], pair: str,
return tradesdata
def store_trades_file(datadir: Optional[Path], pair: str,
def store_trades_file(datadir: Path, pair: str,
data: list, is_zip: bool = True):
"""
Stores tickerdata to file
@ -329,17 +329,14 @@ def refresh_backtest_ohlcv_data(exchange: Exchange, pairs: List[str], timeframes
return pairs_not_available
def download_trades_history(datadir: Optional[Path],
exchange: Optional[Exchange],
def download_trades_history(datadir: Path,
exchange: Exchange,
pair: str,
timerange: Optional[TimeRange] = None) -> bool:
"""
Download trade history from the exchange.
Appends to previously downloaded trades data.
"""
if not exchange:
raise OperationalException(
"Exchange needs to be initialized to download data")
try:
since = timerange.startts * 1000 if timerange and timerange.starttype == 'date' else None

View File

@ -18,7 +18,7 @@ from freqtrade.data.history import (download_pair_history,
refresh_backtest_ohlcv_data,
load_tickerdata_file, pair_data_filename,
pair_trades_filename,
trim_tickerlist)
trim_tickerlist, refresh_backtest_trades_data)
from freqtrade.exchange import timeframe_to_minutes
from freqtrade.misc import file_dump_json
from freqtrade.strategy.default_strategy import DefaultStrategy
@ -583,3 +583,27 @@ def test_download_data_no_markets(mocker, default_conf, caplog, testdatadir):
assert "ETH/BTC" in unav_pairs
assert "XRP/BTC" in unav_pairs
assert log_has("Skipping pair ETH/BTC...", caplog)
def test_refresh_backtest_trades_data(mocker, default_conf, markets, caplog, testdatadir):
dl_mock = mocker.patch('freqtrade.data.history.download_trades_history', MagicMock())
mocker.patch(
'freqtrade.exchange.Exchange.markets', PropertyMock(return_value=markets)
)
mocker.patch.object(Path, "exists", MagicMock(return_value=True))
mocker.patch.object(Path, "unlink", MagicMock())
ex = get_patched_exchange(mocker, default_conf)
timerange = TimeRange.parse_timerange("20190101-20190102")
unavailable_pairs = refresh_backtest_trades_data(exchange=ex,
pairs=["ETH/BTC", "XRP/BTC", "XRP/ETH"],
datadir=testdatadir,
timerange=timerange, erase=True
)
assert dl_mock.call_count == 2
assert dl_mock.call_args[1]['timerange'].starttype == 'date'
assert log_has("Downloading trades for pair ETH/BTC.", caplog)
assert unavailable_pairs == ["XRP/ETH"]
assert log_has("Skipping pair XRP/ETH...", caplog)