Improve naming of apiserver variables

This commit is contained in:
Matthias 2021-07-10 11:19:23 +02:00
parent ad26b0dad0
commit 52ae95b2a5
3 changed files with 23 additions and 19 deletions

View File

@ -390,6 +390,6 @@ class Arguments:
# Add webserver subcommand # Add webserver subcommand
webserver_cmd = subparsers.add_parser('webserver', help='Webserver module.', webserver_cmd = subparsers.add_parser('webserver', help='Webserver module.',
parents=[_common_parser, _strategy_parser]) parents=[_common_parser])
webserver_cmd.set_defaults(func=start_webserver) webserver_cmd.set_defaults(func=start_webserver)
self._build_args(optionlist=ARGS_WEBSERVER, parser=webserver_cmd) self._build_args(optionlist=ARGS_WEBSERVER, parser=webserver_cmd)

View File

@ -40,35 +40,39 @@ async def api_start_backtest(bt_settings: BacktestRequest, background_tasks: Bac
asyncio.set_event_loop(asyncio.new_event_loop()) asyncio.set_event_loop(asyncio.new_event_loop())
try: try:
# Reload strategy # Reload strategy
lastconfig = ApiServer._lastbacktestconfig lastconfig = ApiServer._bt_last_config
strat = StrategyResolver.load_strategy(btconfig) strat = StrategyResolver.load_strategy(btconfig)
if (not ApiServer._bt if (
or lastconfig.get('timeframe') != strat.timeframe not ApiServer._bt
or lastconfig.get('dry_run_wallet') != btconfig.get('dry_run_wallet', 0)): or lastconfig.get('timeframe') != strat.timeframe
or lastconfig.get('dry_run_wallet') != btconfig.get('dry_run_wallet', 0)
):
from freqtrade.optimize.backtesting import Backtesting from freqtrade.optimize.backtesting import Backtesting
ApiServer._bt = Backtesting(btconfig) ApiServer._bt = Backtesting(btconfig)
# Only reload data if timeframe or timerange changed. # Only reload data if timeframe or timerange changed.
if (not ApiServer._backtestdata or not ApiServer._bt_timerange if (
or lastconfig.get('timerange') != btconfig['timerange'] not ApiServer._bt_data
or lastconfig.get('stake_amount') != btconfig.get('stake_amount') or not ApiServer._bt_timerange
or lastconfig.get('enable_protections') != btconfig.get('enable_protections') or lastconfig.get('timerange') != btconfig['timerange']
or lastconfig.get('protections') != btconfig.get('protections', []) or lastconfig.get('stake_amount') != btconfig.get('stake_amount')
or lastconfig.get('timeframe') != strat.timeframe): or lastconfig.get('enable_protections') != btconfig.get('enable_protections')
or lastconfig.get('protections') != btconfig.get('protections', [])
or lastconfig.get('timeframe') != strat.timeframe
):
lastconfig['timerange'] = btconfig['timerange'] lastconfig['timerange'] = btconfig['timerange']
lastconfig['protections'] = btconfig.get('protections', []) lastconfig['protections'] = btconfig.get('protections', [])
lastconfig['enable_protections'] = btconfig.get('enable_protections') lastconfig['enable_protections'] = btconfig.get('enable_protections')
lastconfig['dry_run_wallet'] = btconfig.get('dry_run_wallet') lastconfig['dry_run_wallet'] = btconfig.get('dry_run_wallet')
lastconfig['timeframe'] = strat.timeframe lastconfig['timeframe'] = strat.timeframe
ApiServer._backtestdata, ApiServer._bt_timerange = ApiServer._bt.load_bt_data() ApiServer._bt_data, ApiServer._bt_timerange = ApiServer._bt.load_bt_data()
ApiServer._bt.abort = False ApiServer._bt.abort = False
min_date, max_date = ApiServer._bt.backtest_one_strategy( min_date, max_date = ApiServer._bt.backtest_one_strategy(
strat, ApiServer._backtestdata, strat, ApiServer._bt_data, ApiServer._bt_timerange)
ApiServer._bt_timerange)
ApiServer._bt.results = generate_backtest_stats( ApiServer._bt.results = generate_backtest_stats(
ApiServer._backtestdata, ApiServer._bt.all_results, ApiServer._bt_data, ApiServer._bt.all_results,
min_date=min_date, max_date=max_date) min_date=min_date, max_date=max_date)
logger.info("Backtest finished.") logger.info("Backtest finished.")
@ -140,8 +144,8 @@ def api_delete_backtest():
if ApiServer._bt: if ApiServer._bt:
del ApiServer._bt del ApiServer._bt
ApiServer._bt = None ApiServer._bt = None
del ApiServer._backtestdata del ApiServer._bt_data
ApiServer._backtestdata = None ApiServer._bt_data = None
logger.info("Backtesting reset") logger.info("Backtesting reset")
return { return {
"status": "reset", "status": "reset",

View File

@ -35,9 +35,9 @@ class ApiServer(RPCHandler):
_rpc: RPC _rpc: RPC
# Backtesting type: Backtesting # Backtesting type: Backtesting
_bt = None _bt = None
_backtestdata = None _bt_data = None
_bt_timerange = None _bt_timerange = None
_lastbacktestconfig: Dict[str, Any] = {} _bt_last_config: Dict[str, Any] = {}
_has_rpc: bool = False _has_rpc: bool = False
_bgtask_running: bool = False _bgtask_running: bool = False
_config: Dict[str, Any] = {} _config: Dict[str, Any] = {}