extract backtesting abort functionality
This commit is contained in:
@@ -189,6 +189,15 @@ class Backtesting:
|
||||
self.rejected_trades = 0
|
||||
self.dataprovider.clear_cache()
|
||||
|
||||
def check_abort(self):
|
||||
"""
|
||||
Check if abort was requested, raise DependencyException if that's the case
|
||||
Only applies to Interactive backtest mode (webserver mode)
|
||||
"""
|
||||
if self.abort:
|
||||
self.abort = False
|
||||
raise DependencyException("Stop requested")
|
||||
|
||||
def _get_ohlcv_as_lists(self, processed: Dict[str, DataFrame]) -> Dict[str, Tuple]:
|
||||
"""
|
||||
Helper function to convert a processed dataframes into lists for performance reasons.
|
||||
@@ -203,8 +212,7 @@ class Backtesting:
|
||||
|
||||
# Create dict with data
|
||||
for pair, pair_data in processed.items():
|
||||
if self.abort:
|
||||
raise DependencyException("Stop requested")
|
||||
self.check_abort()
|
||||
self.progress.increment()
|
||||
if not pair_data.empty:
|
||||
pair_data.loc[:, 'buy'] = 0 # cleanup if buy_signal is exist
|
||||
@@ -422,8 +430,7 @@ class Backtesting:
|
||||
# Loop timerange and get candle for each pair at that point in time
|
||||
while tmp <= end_date:
|
||||
open_trade_count_start = open_trade_count
|
||||
if self.abort:
|
||||
raise DependencyException("Stop requested")
|
||||
self.check_abort()
|
||||
for i, pair in enumerate(data):
|
||||
row_index = indexes[pair]
|
||||
try:
|
||||
|
@@ -52,8 +52,8 @@ async def api_start_backtest(bt_settings: BacktestRequest, background_tasks: Bac
|
||||
# TODO: Investigate if enabling protections can be dynamically ingested from here...
|
||||
from freqtrade.optimize.backtesting import Backtesting
|
||||
ApiServer._bt = Backtesting(btconfig)
|
||||
# Reset data if backtesting is reloaded
|
||||
|
||||
# Only reload data if timeframe or timerange changed.
|
||||
if (not ApiServer._backtestdata or not ApiServer._bt_timerange
|
||||
or lastconfig.get('timerange') != btconfig['timerange']
|
||||
or lastconfig.get('timeframe') != strat.timeframe):
|
||||
|
Reference in New Issue
Block a user