Optimise the multiple usages of the same timestamp.
This commit is contained in:
parent
e67a54f7a9
commit
451eca51c8
@ -462,11 +462,11 @@ class Backtesting:
|
|||||||
|
|
||||||
def _enter_trade(self, pair: str, row: Tuple, stake_amount: Optional[float] = None,
|
def _enter_trade(self, pair: str, row: Tuple, stake_amount: Optional[float] = None,
|
||||||
trade: Optional[LocalTrade] = None) -> Optional[LocalTrade]:
|
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
|
# let's call the custom entry price, using the open price as default price
|
||||||
propose_rate = strategy_safe_wrapper(self.strategy.custom_entry_price,
|
propose_rate = strategy_safe_wrapper(self.strategy.custom_entry_price,
|
||||||
default_retval=row[OPEN_IDX])(
|
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
|
proposed_rate=row[OPEN_IDX]) # default value is the open rate
|
||||||
|
|
||||||
# Move rate to within the candle's low/high 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,
|
stake_amount = strategy_safe_wrapper(self.strategy.custom_stake_amount,
|
||||||
default_retval=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)
|
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)
|
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 pos_adjust:
|
||||||
if not strategy_safe_wrapper(self.strategy.confirm_trade_entry, default_retval=True)(
|
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,
|
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
|
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):
|
||||||
@ -511,7 +511,7 @@ class Backtesting:
|
|||||||
trade = LocalTrade(
|
trade = LocalTrade(
|
||||||
pair=pair,
|
pair=pair,
|
||||||
open_rate=propose_rate,
|
open_rate=propose_rate,
|
||||||
open_date=row[DATE_IDX].to_pydatetime(),
|
open_date=current_time,
|
||||||
stake_amount=stake_amount,
|
stake_amount=stake_amount,
|
||||||
amount=amount,
|
amount=amount,
|
||||||
fee_open=self.fee,
|
fee_open=self.fee,
|
||||||
@ -531,9 +531,9 @@ class Backtesting:
|
|||||||
side="buy",
|
side="buy",
|
||||||
order_type="market",
|
order_type="market",
|
||||||
status="closed",
|
status="closed",
|
||||||
order_date=row[DATE_IDX].to_pydatetime(),
|
order_date=current_time,
|
||||||
order_filled_date=row[DATE_IDX].to_pydatetime(),
|
order_filled_date=current_time,
|
||||||
order_update_date=row[DATE_IDX].to_pydatetime(),
|
order_update_date=current_time,
|
||||||
price=propose_rate,
|
price=propose_rate,
|
||||||
average=propose_rate,
|
average=propose_rate,
|
||||||
amount=amount,
|
amount=amount,
|
||||||
|
Loading…
Reference in New Issue
Block a user