remove filled date logic

This commit is contained in:
adriance 2022-03-14 13:42:52 +08:00
parent a750369796
commit bea38a2e7c
3 changed files with 7 additions and 18 deletions

View File

@ -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', 'buy_filled_date', 'close_date',
BT_DATA_COLUMNS = ['pair', 'stake_amount', 'amount', 'open_date', 'close_date',
'open_rate', 'close_rate',
'fee_open', 'fee_close', 'trade_duration',
'profit_ratio', 'profit_abs', 'sell_reason',
@ -316,7 +316,6 @@ 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

View File

@ -356,7 +356,7 @@ class Backtesting:
trade_dur: int) -> float:
leverage = trade.leverage or 1.0
is_short = trade.is_short or False
filled_dur = int((trade.close_date_utc - trade.buy_filled_date_utc).total_seconds() // 60)
"""
Get close rate for backtesting result
"""
@ -378,7 +378,7 @@ class Backtesting:
# Special case: trailing triggers within same candle as trade opened. Assume most
# pessimistic price movement, which is moving just enough to arm stoploss and
# immediately going down to stop price.
if sell.sell_type == SellType.TRAILING_STOP_LOSS and (trade_dur == 0 or filled_dur == 0):
if sell.sell_type == SellType.TRAILING_STOP_LOSS and trade_dur == 0:
if (
not self.strategy.use_custom_stoploss and self.strategy.trailing_stop
and self.strategy.trailing_only_offset_is_reached
@ -425,7 +425,7 @@ class Backtesting:
if is_short:
close_rate = (trade.open_rate *
(1 - trade.fee_open) - trade.open_rate * roi / leverage) / (trade.fee_close + 1)
if (trade_dur > 0 and filled_dur > 0 and trade_dur == roi_entry
if (trade_dur > 0 and trade_dur == roi_entry
and roi_entry % self.timeframe_min == 0
and sell_row[OPEN_IDX] < close_rate):
# new ROI entry came into effect.
@ -435,7 +435,7 @@ class Backtesting:
close_rate = - (trade.open_rate * roi / leverage + trade.open_rate *
(1 + trade.fee_open)) / (trade.fee_close - 1)
if (trade_dur > 0 and filled_dur > 0 and trade_dur == roi_entry
if (trade_dur > 0 and trade_dur == roi_entry
and roi_entry % self.timeframe_min == 0
and sell_row[OPEN_IDX] > close_rate):
# new ROI entry came into effect.
@ -444,7 +444,7 @@ class Backtesting:
if is_short:
if (
(trade_dur == 0 or filled_dur == 0)
trade_dur == 0
# Red candle (for longs), TODO: green candle (for shorts)
and sell_row[OPEN_IDX] < sell_row[CLOSE_IDX] # Red candle
and trade.open_rate > sell_row[OPEN_IDX] # trade-open below open_rate
@ -457,7 +457,7 @@ class Backtesting:
raise ValueError("Opening candle ROI on red candles.")
else:
if (
(trade_dur == 0 or filled_dur == 0)
trade_dur == 0
# Red candle (for longs), TODO: green candle (for shorts)
and sell_row[OPEN_IDX] > sell_row[CLOSE_IDX] # Red candle
and trade.open_rate < sell_row[OPEN_IDX] # trade-open below open_rate

View File

@ -302,7 +302,6 @@ class LocalTrade():
amount: float = 0.0
amount_requested: Optional[float] = None
open_date: datetime
buy_filled_date: Optional[datetime] = None
close_date: Optional[datetime] = None
open_order_id: Optional[str] = None
# absolute value of the stop loss
@ -367,10 +366,6 @@ class LocalTrade():
else:
return self.amount
@property
def buy_filled_date_utc(self):
return self.buy_filled_date.replace(tzinfo=timezone.utc)
@property
def open_date_utc(self):
return self.open_date.replace(tzinfo=timezone.utc)
@ -449,11 +444,6 @@ 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)
if self.buy_filled_date else None),
'buy_filled_timestamp': int(self.buy_filled_date.replace(
tzinfo=timezone.utc).timestamp() * 1000) if self.buy_filled_date else None,
'close_date': (self.close_date.strftime(DATETIME_PRINT_FORMAT)
if self.close_date else None),
'close_timestamp': int(self.close_date.replace(