add filled time
This commit is contained in:
parent
14bce0b1c3
commit
d579febfec
@ -19,7 +19,7 @@ from freqtrade.persistence import LocalTrade, Trade, init_db
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Newest format
|
||||
BT_DATA_COLUMNS = ['pair', 'stake_amount', 'amount', 'open_date', 'close_date',
|
||||
BT_DATA_COLUMNS = ['pair', 'stake_amount', 'amount', 'open_date', 'buy_filled_date', 'close_date',
|
||||
'open_rate', 'close_rate',
|
||||
'fee_open', 'fee_close', 'trade_duration',
|
||||
'profit_ratio', 'profit_abs', 'sell_reason',
|
||||
@ -316,6 +316,7 @@ def trade_list_to_dataframe(trades: List[LocalTrade]) -> pd.DataFrame:
|
||||
if len(df) > 0:
|
||||
df.loc[:, 'close_date'] = pd.to_datetime(df['close_date'], utc=True)
|
||||
df.loc[:, 'open_date'] = pd.to_datetime(df['open_date'], utc=True)
|
||||
df.loc[:, 'buy_filled_date'] = pd.to_datetime(df['buy_filled_date'], utc=True)
|
||||
df.loc[:, 'close_rate'] = df['close_rate'].astype('float64')
|
||||
return df
|
||||
|
||||
|
@ -534,7 +534,7 @@ class Backtesting:
|
||||
if sell.sell_flag:
|
||||
trade.close_date = sell_candle_time
|
||||
|
||||
trade_dur = int((trade.close_date_utc - trade.filled_date_utc).total_seconds() // 60)
|
||||
trade_dur = int((trade.close_date_utc - trade.buy_filled_date_utc).total_seconds() // 60)
|
||||
try:
|
||||
closerate = self._get_close_rate(sell_row, trade, sell, trade_dur)
|
||||
except ValueError:
|
||||
@ -960,6 +960,7 @@ class Backtesting:
|
||||
if order and self._get_order_filled(order.price, row):
|
||||
order.close_bt_order(current_time)
|
||||
trade.open_order_id = None
|
||||
trade.buy_filled_date = current_time
|
||||
LocalTrade.add_bt_trade(trade)
|
||||
self.wallets.update()
|
||||
|
||||
|
@ -302,6 +302,7 @@ class LocalTrade():
|
||||
amount: float = 0.0
|
||||
amount_requested: Optional[float] = None
|
||||
open_date: datetime
|
||||
buy_filled_date: datetime
|
||||
close_date: Optional[datetime] = None
|
||||
open_order_id: Optional[str] = None
|
||||
# absolute value of the stop loss
|
||||
@ -367,8 +368,8 @@ class LocalTrade():
|
||||
return self.amount
|
||||
|
||||
@property
|
||||
def filled_date_utc(self):
|
||||
return self.select_order('buy', is_open=False).order_filled_date.replace(tzinfo=timezone.utc)
|
||||
def buy_filled_date_utc(self):
|
||||
return self.buy_filled_date.replace(tzinfo=timezone.utc)
|
||||
|
||||
@property
|
||||
def open_date_utc(self):
|
||||
@ -448,6 +449,9 @@ class LocalTrade():
|
||||
'open_rate_requested': self.open_rate_requested,
|
||||
'open_trade_value': round(self.open_trade_value, 8),
|
||||
|
||||
'buy_filled_date': self.buy_filled_date.strftime(DATETIME_PRINT_FORMAT),
|
||||
'buy_filled_timestamp': int(self.buy_filled_date.replace(tzinfo=timezone.utc).timestamp() * 1000),
|
||||
|
||||
'close_date': (self.close_date.strftime(DATETIME_PRINT_FORMAT)
|
||||
if self.close_date else None),
|
||||
'close_timestamp': int(self.close_date.replace(
|
||||
|
Loading…
Reference in New Issue
Block a user