Support multis-strategy backtests with protections

This commit is contained in:
Matthias
2020-11-25 09:53:13 +01:00
parent a3f9cd2c26
commit 75a5161650
5 changed files with 64 additions and 4 deletions

View File

@@ -120,8 +120,10 @@ class Backtesting:
self.fee = self.exchange.get_fee(symbol=self.pairlists.whitelist[0])
Trade.use_db = False
Trade.reset_trades()
PairLocks.timeframe = self.config['timeframe']
PairLocks.use_db = False
PairLocks.reset_locks()
if self.config.get('enable_protections', False):
self.protections = ProtectionManager(self.config)
@@ -130,6 +132,11 @@ class Backtesting:
# Load one (first) strategy
self._set_strategy(self.strategylist[0])
def __del__(self):
LoggingMixin.show_output = True
PairLocks.use_db = True
Trade.use_db = True
def _set_strategy(self, strategy):
"""
Load strategy into backtesting
@@ -321,6 +328,13 @@ class Backtesting:
f"max_open_trades: {max_open_trades}, position_stacking: {position_stacking}"
)
trades = []
PairLocks.use_db = False
Trade.use_db = False
if enable_protections:
# Reset persisted data - used for protections only
PairLocks.reset_locks()
Trade.reset_trades()
# Use dict of lists with data for performance
# (looping lists is a lot faster than pandas DataFrames)