use filled time calculate duration

This commit is contained in:
adriance 2022-03-09 21:55:13 +08:00
parent 82e0eca128
commit 1c86e69c34
2 changed files with 5 additions and 1 deletions

View File

@ -534,7 +534,7 @@ class Backtesting:
if sell.sell_flag:
trade.close_date = sell_candle_time
trade_dur = int((trade.close_date_utc - trade.open_date_utc).total_seconds() // 60)
trade_dur = int((trade.close_date_utc - trade.filled_date_utc).total_seconds() // 60)
try:
closerate = self._get_close_rate(sell_row, trade, sell, trade_dur)
except ValueError:

View File

@ -366,6 +366,10 @@ class LocalTrade():
else:
return self.amount
@property
def filled_date_utc(self):
return self.select_order('buy', is_open=False).order_filled_date.replace(tzinfo=timezone.utc)
@property
def open_date_utc(self):
return self.open_date.replace(tzinfo=timezone.utc)