Add confirm_trade_exit and confirm_trade_entry to backtesting
This commit is contained in:
parent
dd5873ef24
commit
6856963aef
@ -30,7 +30,6 @@ from freqtrade.strategy.interface import IStrategy, SellCheckTuple, SellType
|
|||||||
from freqtrade.strategy.strategy_wrapper import strategy_safe_wrapper
|
from freqtrade.strategy.strategy_wrapper import strategy_safe_wrapper
|
||||||
from freqtrade.wallets import Wallets
|
from freqtrade.wallets import Wallets
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Indexes for backtest tuples
|
# Indexes for backtest tuples
|
||||||
@ -252,8 +251,17 @@ class Backtesting:
|
|||||||
sell = self.strategy.should_sell(trade, sell_row[OPEN_IDX], # type: ignore
|
sell = self.strategy.should_sell(trade, sell_row[OPEN_IDX], # type: ignore
|
||||||
sell_row[DATE_IDX], sell_row[BUY_IDX], sell_row[SELL_IDX],
|
sell_row[DATE_IDX], sell_row[BUY_IDX], sell_row[SELL_IDX],
|
||||||
low=sell_row[LOW_IDX], high=sell_row[HIGH_IDX])
|
low=sell_row[LOW_IDX], high=sell_row[HIGH_IDX])
|
||||||
if sell.sell_flag:
|
|
||||||
|
|
||||||
|
time_in_force = self.strategy.order_time_in_force['sell']
|
||||||
|
|
||||||
|
# confirm_trade_exit
|
||||||
|
if not strategy_safe_wrapper(self.strategy.confirm_trade_exit, default_retval=False)(
|
||||||
|
pair=trade.pair, trade=trade, order_type='limit', amount=trade.amount, rate=sell_row[LOW_IDX],
|
||||||
|
time_in_force=time_in_force,
|
||||||
|
sell_reason=sell.sell_type.value):
|
||||||
|
return None
|
||||||
|
|
||||||
|
if sell.sell_flag:
|
||||||
trade.close_date = sell_row[DATE_IDX]
|
trade.close_date = sell_row[DATE_IDX]
|
||||||
trade.sell_reason = sell.sell_type.value
|
trade.sell_reason = sell.sell_type.value
|
||||||
trade_dur = int((trade.close_date_utc - trade.open_date_utc).total_seconds() // 60)
|
trade_dur = int((trade.close_date_utc - trade.open_date_utc).total_seconds() // 60)
|
||||||
@ -271,6 +279,15 @@ class Backtesting:
|
|||||||
except DependencyException:
|
except DependencyException:
|
||||||
return None
|
return None
|
||||||
min_stake_amount = self.exchange.get_min_pair_stake_amount(pair, row[OPEN_IDX], -0.05)
|
min_stake_amount = self.exchange.get_min_pair_stake_amount(pair, row[OPEN_IDX], -0.05)
|
||||||
|
|
||||||
|
order_type = self.strategy.order_types['buy']
|
||||||
|
time_in_force = self.strategy.order_time_in_force['sell']
|
||||||
|
# confirm_trade_entry
|
||||||
|
if not strategy_safe_wrapper(self.strategy.confirm_trade_entry, default_retval=True)(
|
||||||
|
pair=pair, order_type=order_type, amount=stake_amount, rate=row[OPEN_IDX],
|
||||||
|
time_in_force=time_in_force):
|
||||||
|
return None
|
||||||
|
|
||||||
if stake_amount and (not min_stake_amount or stake_amount > min_stake_amount):
|
if stake_amount and (not min_stake_amount or stake_amount > min_stake_amount):
|
||||||
# Enter trade
|
# Enter trade
|
||||||
trade = LocalTrade(
|
trade = LocalTrade(
|
||||||
|
Loading…
Reference in New Issue
Block a user