Merge branch 'feat/short' into fs_fix

This commit is contained in:
adriance
2022-03-12 16:50:27 +08:00
36 changed files with 259 additions and 143 deletions

View File

@@ -127,10 +127,9 @@ class Backtesting:
self.config['startup_candle_count'] = self.required_startup
self.exchange.validate_required_startup_candles(self.required_startup, self.timeframe)
# TODO-lev: This should come from the configuration setting or better a
# TODO-lev: combination of config/strategy "use_shorts"(?) and "can_short" from the exchange
self.trading_mode: TradingMode = config.get('trading_mode', TradingMode.SPOT)
self.margin_mode: MarginMode = config.get('margin_mode', MarginMode.NONE)
# strategies which define "can_short=True" will fail to load in Spot mode.
self._can_short = self.trading_mode != TradingMode.SPOT
self.progress = BTProgress()
@@ -542,7 +541,7 @@ class Backtesting:
return None
# call the custom exit price,with default value as previous closerate
current_profit = trade.calc_profit_ratio(closerate)
order_type = self.strategy.order_types['sell']
order_type = self.strategy.order_types['exit']
if sell.sell_type in (SellType.SELL_SIGNAL, SellType.CUSTOM_SELL):
# Custom exit pricing only for sell-signals
if order_type == 'limit':
@@ -650,7 +649,7 @@ class Backtesting:
current_time = row[DATE_IDX].to_pydatetime()
entry_tag = row[ENTER_TAG_IDX] if len(row) >= ENTER_TAG_IDX + 1 else None
# let's call the custom entry price, using the open price as default price
order_type = self.strategy.order_types['buy']
order_type = self.strategy.order_types['entry']
propose_rate = row[OPEN_IDX]
if order_type == 'limit':
propose_rate = strategy_safe_wrapper(self.strategy.custom_entry_price,
@@ -693,7 +692,7 @@ class Backtesting:
# In case of pos adjust, still return the original trade
# If not pos adjust, trade is None
return trade
order_type = self.strategy.order_types['buy']
order_type = self.strategy.order_types['entry']
time_in_force = self.strategy.order_time_in_force['entry']
if not pos_adjust: