From e67a54f7a979e8bb873875aac3e6a9fac06d40d3 Mon Sep 17 00:00:00 2001 From: Reigo Reinmets Date: Sun, 23 Jan 2022 20:51:15 +0200 Subject: [PATCH 1/2] Fix missing order time info in backtesting. --- freqtrade/optimize/backtesting.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index 9cfeedd75..ea6a4082d 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -531,6 +531,9 @@ class Backtesting: side="buy", order_type="market", status="closed", + order_date=row[DATE_IDX].to_pydatetime(), + order_filled_date=row[DATE_IDX].to_pydatetime(), + order_update_date=row[DATE_IDX].to_pydatetime(), price=propose_rate, average=propose_rate, amount=amount, From 451eca51c83e78c11b508f04a003efb6f62b352d Mon Sep 17 00:00:00 2001 From: Reigo Reinmets Date: Sun, 23 Jan 2022 20:58:25 +0200 Subject: [PATCH 2/2] Optimise the multiple usages of the same timestamp. --- freqtrade/optimize/backtesting.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index ea6a4082d..8d5dc77d6 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -462,11 +462,11 @@ class Backtesting: def _enter_trade(self, pair: str, row: Tuple, stake_amount: Optional[float] = None, trade: Optional[LocalTrade] = None) -> Optional[LocalTrade]: - + current_time = row[DATE_IDX].to_pydatetime() # let's call the custom entry price, using the open price as default price propose_rate = strategy_safe_wrapper(self.strategy.custom_entry_price, default_retval=row[OPEN_IDX])( - pair=pair, current_time=row[DATE_IDX].to_pydatetime(), + pair=pair, current_time=current_time, proposed_rate=row[OPEN_IDX]) # default value is the open rate # Move rate to within the candle's low/high rate @@ -484,7 +484,7 @@ class Backtesting: stake_amount = strategy_safe_wrapper(self.strategy.custom_stake_amount, default_retval=stake_amount)( - pair=pair, current_time=row[DATE_IDX].to_pydatetime(), current_rate=propose_rate, + pair=pair, current_time=current_time, current_rate=propose_rate, proposed_stake=stake_amount, min_stake=min_stake_amount, max_stake=max_stake_amount) stake_amount = self.wallets.validate_stake_amount(pair, stake_amount, min_stake_amount) @@ -500,7 +500,7 @@ class Backtesting: if not pos_adjust: if not strategy_safe_wrapper(self.strategy.confirm_trade_entry, default_retval=True)( pair=pair, order_type=order_type, amount=stake_amount, rate=propose_rate, - time_in_force=time_in_force, current_time=row[DATE_IDX].to_pydatetime()): + time_in_force=time_in_force, current_time=current_time): return None if stake_amount and (not min_stake_amount or stake_amount > min_stake_amount): @@ -511,7 +511,7 @@ class Backtesting: trade = LocalTrade( pair=pair, open_rate=propose_rate, - open_date=row[DATE_IDX].to_pydatetime(), + open_date=current_time, stake_amount=stake_amount, amount=amount, fee_open=self.fee, @@ -531,9 +531,9 @@ class Backtesting: side="buy", order_type="market", status="closed", - order_date=row[DATE_IDX].to_pydatetime(), - order_filled_date=row[DATE_IDX].to_pydatetime(), - order_update_date=row[DATE_IDX].to_pydatetime(), + order_date=current_time, + order_filled_date=current_time, + order_update_date=current_time, price=propose_rate, average=propose_rate, amount=amount,