From 06b6726029d80903e52d6aed2c4e7599b106de12 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 28 Feb 2021 09:56:13 +0100 Subject: [PATCH] Support compounding key --- freqtrade/rpc/api_server/api_schemas.py | 3 ++- freqtrade/rpc/api_server/api_v1.py | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/freqtrade/rpc/api_server/api_schemas.py b/freqtrade/rpc/api_server/api_schemas.py index bb611f287..bf5382131 100644 --- a/freqtrade/rpc/api_server/api_schemas.py +++ b/freqtrade/rpc/api_server/api_schemas.py @@ -320,8 +320,9 @@ class BacktestRequest(BaseModel): timeframe: Optional[str] timerange: Optional[str] max_open_trades: Optional[int] - stake_amount: Optional[int] + stake_amount: Optional[Union[float, str]] enable_protections: bool + dry_run_wallet: Optional[float] class BacktestResponse(BaseModel): diff --git a/freqtrade/rpc/api_server/api_v1.py b/freqtrade/rpc/api_server/api_v1.py index c162a57dc..d4f138ee8 100644 --- a/freqtrade/rpc/api_server/api_v1.py +++ b/freqtrade/rpc/api_server/api_v1.py @@ -285,12 +285,15 @@ async def api_start_backtest(bt_settings: BacktestRequest, background_tasks: Bac asyncio.set_event_loop(asyncio.new_event_loop()) try: # Reload strategy + lastconfig = ApiServer._lastbacktestconfig strat = StrategyResolver.load_strategy(btconfig) if (not ApiServer._bt - or ApiServer._lastbacktestconfig.get('timeframe') != strat.timeframe - or ApiServer._lastbacktestconfig.get('enable_protections') != btconfig.get('enable_protections') - or ApiServer._lastbacktestconfig.get('protections') != btconfig.get('protections', [])): + 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('dry_run_wallet') != btconfig.get('dry_run_wallet', 0) + ): # TODO: Investigate if enabling protections can be dynamically ingested from here... from freqtrade.optimize.backtesting import Backtesting ApiServer._bt = Backtesting(btconfig) @@ -299,11 +302,12 @@ async def api_start_backtest(bt_settings: BacktestRequest, background_tasks: Bac ApiServer._backtestdata = None if (not ApiServer._backtestdata or not ApiServer._bt_timerange - or ApiServer._lastbacktestconfig.get('timerange') != btconfig['timerange']): - ApiServer._lastbacktestconfig['timerange'] = btconfig['timerange'] - ApiServer._lastbacktestconfig['protections'] = btconfig.get('protections', []) - ApiServer._lastbacktestconfig['enable_protections'] = btconfig.get('enable_protections') - ApiServer._lastbacktestconfig['timeframe'] = strat.timeframe + or lastconfig.get('timerange') != btconfig['timerange']): + lastconfig['timerange'] = btconfig['timerange'] + lastconfig['protections'] = btconfig.get('protections', []) + lastconfig['enable_protections'] = btconfig.get('enable_protections') + lastconfig['dry_run_wallet'] = btconfig.get('dry_run_wallet') + lastconfig['timeframe'] = strat.timeframe ApiServer._backtestdata, ApiServer._bt_timerange = ApiServer._bt.load_bt_data() min_date, max_date = ApiServer._bt.backtest_one_strategy(