Improve test by having multistrat.meta file available

This commit is contained in:
Matthias 2022-04-13 06:55:47 +02:00
parent 4ac54a76af
commit f89b64c972
5 changed files with 20 additions and 6 deletions

View File

@ -168,7 +168,7 @@ def load_and_merge_backtest_result(strategy_name: str, filename: Path, results:
def _get_backtest_files(dirname: Path) -> List[Path]:
return reversed(sorted(dirname.glob('backtest-result-*-[0-9][0-9].json')))
return list(reversed(sorted(dirname.glob('backtest-result-*-[0-9][0-9].json'))))
def get_backtest_resultlist(dirname: Path):

View File

@ -1,7 +1,7 @@
import asyncio
import logging
from copy import deepcopy
from typing import List
from typing import Any, Dict, List
from fastapi import APIRouter, BackgroundTasks, Depends
@ -215,7 +215,7 @@ def api_backtest_history(config=Depends(get_config), ws_mode=Depends(is_webserve
def api_backtest_history_result(filename: str, strategy: str, config=Depends(get_config), ws_mode=Depends(is_webserver_mode)):
# Get backtest result history, read from metadata files
fn = config['user_data_dir'] / 'backtest_results' / filename
results = {
results: Dict[str, Any] = {
'metadata': {},
'strategy': {},
'strategy_comparison': [],

View File

@ -35,7 +35,8 @@ logger = logging.getLogger(__name__)
# 1.13: forcebuy supports stake_amount
# versions 2.xx -> futures/short branch
# 2.14: Add entry/exit orders to trade response
API_VERSION = 2.14
# 2.15: Add backtest history endpoints
API_VERSION = 2.15
# Public API, requires no auth.
router_public = APIRouter()

View File

@ -1597,8 +1597,9 @@ def test_api_backtest_history(botclient, mocker, testdatadir):
rc = client_get(client, f"{BASE_URI}/backtest/history")
assert_response(rc)
result = rc.json()
assert len(result) == 1
assert len(result) == 3
fn = result[0]['filename']
assert fn == "backtest-result_multistrat.json"
strategy = result[0]['strategy']
rc = client_get(client, f"{BASE_URI}/backtest/history/result?filename={fn}&strategy={strategy}")
assert_response(rc)
@ -1607,7 +1608,9 @@ def test_api_backtest_history(botclient, mocker, testdatadir):
assert result2['status'] == 'ended'
assert not result2['running']
assert result2['progress'] == 1
assert result2['backtest_result']['strategy'][CURRENT_TEST_STRATEGY]
# Only one strategy loaded - even though we use multiresult
assert len(result2['backtest_result']['strategy']) == 1
assert result2['backtest_result']['strategy'][strategy]
def test_health(botclient):

View File

@ -0,0 +1,10 @@
{
"StrategyTestV2": {
"run_id": "430d0271075ef327edbb23088f4db4ebe51a3dbf",
"backtest_start_time": 1648904006
},
"TestStrategy": {
"run_id": "110d0271075ef327edbb23085102b4ebe51a3d55",
"backtest_start_time": 1648904006
}
}