Don't store 'stoploss_last_updated' explicitly
it can easily be derived from the very last stoploss order.
This commit is contained in:
@@ -1184,7 +1184,6 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
order_obj = Order.parse_from_ccxt_object(stoploss_order, trade.pair, 'stoploss',
|
order_obj = Order.parse_from_ccxt_object(stoploss_order, trade.pair, 'stoploss',
|
||||||
trade.amount, stop_price)
|
trade.amount, stop_price)
|
||||||
trade.orders.append(order_obj)
|
trade.orders.append(order_obj)
|
||||||
trade.stoploss_last_update = datetime.now(timezone.utc)
|
|
||||||
return True
|
return True
|
||||||
except InsufficientFundsError as e:
|
except InsufficientFundsError as e:
|
||||||
logger.warning(f"Unable to place stoploss order {e}.")
|
logger.warning(f"Unable to place stoploss order {e}.")
|
||||||
|
|||||||
@@ -91,7 +91,6 @@ def migrate_trades_and_orders_table(
|
|||||||
is_stop_loss_trailing = get_column_def(
|
is_stop_loss_trailing = get_column_def(
|
||||||
cols, 'is_stop_loss_trailing',
|
cols, 'is_stop_loss_trailing',
|
||||||
f'coalesce({stop_loss_pct}, 0.0) <> coalesce({initial_stop_loss_pct}, 0.0)')
|
f'coalesce({stop_loss_pct}, 0.0) <> coalesce({initial_stop_loss_pct}, 0.0)')
|
||||||
stoploss_last_update = get_column_def(cols, 'stoploss_last_update', 'null')
|
|
||||||
max_rate = get_column_def(cols, 'max_rate', '0.0')
|
max_rate = get_column_def(cols, 'max_rate', '0.0')
|
||||||
min_rate = get_column_def(cols, 'min_rate', 'null')
|
min_rate = get_column_def(cols, 'min_rate', 'null')
|
||||||
exit_reason = get_column_def(cols, 'sell_reason', get_column_def(cols, 'exit_reason', 'null'))
|
exit_reason = get_column_def(cols, 'sell_reason', get_column_def(cols, 'exit_reason', 'null'))
|
||||||
@@ -159,7 +158,7 @@ def migrate_trades_and_orders_table(
|
|||||||
open_rate_requested, close_rate, close_rate_requested, close_profit,
|
open_rate_requested, close_rate, close_rate_requested, close_profit,
|
||||||
stake_amount, amount, amount_requested, open_date, close_date,
|
stake_amount, amount, amount_requested, open_date, close_date,
|
||||||
stop_loss, stop_loss_pct, initial_stop_loss, initial_stop_loss_pct,
|
stop_loss, stop_loss_pct, initial_stop_loss, initial_stop_loss_pct,
|
||||||
is_stop_loss_trailing, stoploss_last_update,
|
is_stop_loss_trailing,
|
||||||
max_rate, min_rate, exit_reason, exit_order_status, strategy, enter_tag,
|
max_rate, min_rate, exit_reason, exit_order_status, strategy, enter_tag,
|
||||||
timeframe, open_trade_value, close_profit_abs,
|
timeframe, open_trade_value, close_profit_abs,
|
||||||
trading_mode, leverage, liquidation_price, is_short,
|
trading_mode, leverage, liquidation_price, is_short,
|
||||||
@@ -179,7 +178,6 @@ def migrate_trades_and_orders_table(
|
|||||||
{initial_stop_loss} initial_stop_loss,
|
{initial_stop_loss} initial_stop_loss,
|
||||||
{initial_stop_loss_pct} initial_stop_loss_pct,
|
{initial_stop_loss_pct} initial_stop_loss_pct,
|
||||||
{is_stop_loss_trailing} is_stop_loss_trailing,
|
{is_stop_loss_trailing} is_stop_loss_trailing,
|
||||||
{stoploss_last_update} stoploss_last_update,
|
|
||||||
{max_rate} max_rate, {min_rate} min_rate,
|
{max_rate} max_rate, {min_rate} min_rate,
|
||||||
case when {exit_reason} = 'sell_signal' then 'exit_signal'
|
case when {exit_reason} = 'sell_signal' then 'exit_signal'
|
||||||
when {exit_reason} = 'custom_sell' then 'custom_exit'
|
when {exit_reason} = 'custom_sell' then 'custom_exit'
|
||||||
|
|||||||
@@ -364,8 +364,6 @@ class LocalTrade:
|
|||||||
# percentage value of the initial stop loss
|
# percentage value of the initial stop loss
|
||||||
initial_stop_loss_pct: Optional[float] = None
|
initial_stop_loss_pct: Optional[float] = None
|
||||||
is_stop_loss_trailing: bool = False
|
is_stop_loss_trailing: bool = False
|
||||||
# last update time of the stoploss order on exchange
|
|
||||||
stoploss_last_update: Optional[datetime] = None
|
|
||||||
# absolute value of the highest reached price
|
# absolute value of the highest reached price
|
||||||
max_rate: Optional[float] = None
|
max_rate: Optional[float] = None
|
||||||
# Lowest price reached
|
# Lowest price reached
|
||||||
@@ -455,8 +453,8 @@ class LocalTrade:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def stoploss_last_update_utc(self):
|
def stoploss_last_update_utc(self):
|
||||||
if self.stoploss_last_update:
|
if self.has_open_sl_orders:
|
||||||
return self.stoploss_last_update.replace(tzinfo=timezone.utc)
|
return max(o.order_date_utc for o in self.open_sl_orders)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -638,10 +636,10 @@ class LocalTrade:
|
|||||||
'stop_loss_abs': self.stop_loss,
|
'stop_loss_abs': self.stop_loss,
|
||||||
'stop_loss_ratio': self.stop_loss_pct if self.stop_loss_pct else None,
|
'stop_loss_ratio': self.stop_loss_pct if self.stop_loss_pct else None,
|
||||||
'stop_loss_pct': (self.stop_loss_pct * 100) if self.stop_loss_pct else None,
|
'stop_loss_pct': (self.stop_loss_pct * 100) if self.stop_loss_pct else None,
|
||||||
'stoploss_last_update': (self.stoploss_last_update.strftime(DATETIME_PRINT_FORMAT)
|
'stoploss_last_update': (self.stoploss_last_update_utc.strftime(DATETIME_PRINT_FORMAT)
|
||||||
if self.stoploss_last_update else None),
|
if self.stoploss_last_update_utc else None),
|
||||||
'stoploss_last_update_timestamp': int(self.stoploss_last_update.replace(
|
'stoploss_last_update_timestamp': int(self.stoploss_last_update_utc.timestamp() * 1000
|
||||||
tzinfo=timezone.utc).timestamp() * 1000) if self.stoploss_last_update else None,
|
) if self.stoploss_last_update_utc else None,
|
||||||
'initial_stop_loss_abs': self.initial_stop_loss,
|
'initial_stop_loss_abs': self.initial_stop_loss,
|
||||||
'initial_stop_loss_ratio': (self.initial_stop_loss_pct
|
'initial_stop_loss_ratio': (self.initial_stop_loss_pct
|
||||||
if self.initial_stop_loss_pct else None),
|
if self.initial_stop_loss_pct else None),
|
||||||
@@ -1378,10 +1376,6 @@ class LocalTrade:
|
|||||||
exit_order_status=data["exit_order_status"],
|
exit_order_status=data["exit_order_status"],
|
||||||
stop_loss=data["stop_loss_abs"],
|
stop_loss=data["stop_loss_abs"],
|
||||||
stop_loss_pct=data["stop_loss_ratio"],
|
stop_loss_pct=data["stop_loss_ratio"],
|
||||||
stoploss_last_update=(
|
|
||||||
datetime.fromtimestamp(data["stoploss_last_update_timestamp"] // 1000,
|
|
||||||
tz=timezone.utc)
|
|
||||||
if data["stoploss_last_update_timestamp"] else None),
|
|
||||||
initial_stop_loss=data["initial_stop_loss_abs"],
|
initial_stop_loss=data["initial_stop_loss_abs"],
|
||||||
initial_stop_loss_pct=data["initial_stop_loss_ratio"],
|
initial_stop_loss_pct=data["initial_stop_loss_ratio"],
|
||||||
min_rate=data["min_rate"],
|
min_rate=data["min_rate"],
|
||||||
@@ -1487,8 +1481,6 @@ class Trade(ModelBase, LocalTrade):
|
|||||||
Float(), nullable=True) # type: ignore
|
Float(), nullable=True) # type: ignore
|
||||||
is_stop_loss_trailing: Mapped[bool] = mapped_column(
|
is_stop_loss_trailing: Mapped[bool] = mapped_column(
|
||||||
nullable=False, default=False) # type: ignore
|
nullable=False, default=False) # type: ignore
|
||||||
# last update time of the stoploss order on exchange
|
|
||||||
stoploss_last_update: Mapped[Optional[datetime]] = mapped_column(nullable=True) # type: ignore
|
|
||||||
# absolute value of the highest reached price
|
# absolute value of the highest reached price
|
||||||
max_rate: Mapped[Optional[float]] = mapped_column(
|
max_rate: Mapped[Optional[float]] = mapped_column(
|
||||||
Float(), nullable=True, default=0.0) # type: ignore
|
Float(), nullable=True, default=0.0) # type: ignore
|
||||||
|
|||||||
Reference in New Issue
Block a user