Merge branch 'freqtrade:develop' into strategy_utils

This commit is contained in:
hippocritical
2023-03-05 12:30:26 +01:00
committed by GitHub
10 changed files with 64 additions and 19 deletions

View File

@@ -27,11 +27,10 @@ class Bybit(Exchange):
"""
_ft_has: Dict = {
"ohlcv_candle_limit": 1000,
"ohlcv_candle_limit": 200,
"ohlcv_has_history": False,
}
_ft_has_futures: Dict = {
"ohlcv_candle_limit": 200,
"ohlcv_has_history": True,
"mark_ohlcv_timeframe": "4h",
"funding_fee_timeframe": "8h",

View File

@@ -120,8 +120,9 @@ class Order(ModelBase):
def __repr__(self):
return (f'Order(id={self.id}, order_id={self.order_id}, trade_id={self.ft_trade_id}, '
f'side={self.side}, order_type={self.order_type}, status={self.status})')
return (f"Order(id={self.id}, order_id={self.order_id}, trade_id={self.ft_trade_id}, "
f"side={self.side}, filled={self.safe_filled}, price={self.safe_price}, "
f"order_type={self.order_type}, status={self.status})")
def update_from_ccxt_object(self, order):
"""
@@ -518,6 +519,8 @@ class LocalTrade():
'close_timestamp': int(self.close_date.replace(
tzinfo=timezone.utc).timestamp() * 1000) if self.close_date else None,
'realized_profit': self.realized_profit or 0.0,
# Close-profit corresponds to relative realized_profit ratio
'realized_profit_ratio': self.close_profit or None,
'close_rate': self.close_rate,
'close_rate_requested': self.close_rate_requested,
'close_profit': self.close_profit, # Deprecated

View File

@@ -250,6 +250,7 @@ class TradeSchema(BaseModel):
profit_fiat: Optional[float]
realized_profit: float
realized_profit_ratio: Optional[float]
exit_reason: Optional[str]
exit_order_status: Optional[str]

View File

@@ -321,31 +321,33 @@ class Telegram(RPCHandler):
and self._rpc._fiat_converter):
msg['profit_fiat'] = self._rpc._fiat_converter.convert_amount(
msg['profit_amount'], msg['stake_currency'], msg['fiat_currency'])
msg['profit_extra'] = (
f" / {msg['profit_fiat']:.3f} {msg['fiat_currency']}")
msg['profit_extra'] = f" / {msg['profit_fiat']:.3f} {msg['fiat_currency']}"
else:
msg['profit_extra'] = ''
msg['profit_extra'] = (
f" ({msg['gain']}: {msg['profit_amount']:.8f} {msg['stake_currency']}"
f"{msg['profit_extra']})")
is_fill = msg['type'] == RPCMessageType.EXIT_FILL
is_sub_trade = msg.get('sub_trade')
is_sub_profit = msg['profit_amount'] != msg.get('cumulative_profit')
profit_prefix = ('Sub ' if is_sub_profit
else 'Cumulative ') if is_sub_trade else ''
profit_prefix = ('Sub ' if is_sub_profit else 'Cumulative ') if is_sub_trade else ''
cp_extra = ''
exit_wording = 'Exited' if is_fill else 'Exiting'
if is_sub_profit and is_sub_trade:
if self._rpc._fiat_converter:
cp_fiat = self._rpc._fiat_converter.convert_amount(
msg['cumulative_profit'], msg['stake_currency'], msg['fiat_currency'])
cp_extra = f" / {cp_fiat:.3f} {msg['fiat_currency']}"
else:
cp_extra = ''
cp_extra = f"*Cumulative Profit:* (`{msg['cumulative_profit']:.8f} " \
f"{msg['stake_currency']}{cp_extra}`)\n"
exit_wording = f"Partially {exit_wording.lower()}"
cp_extra = (
f"*Cumulative Profit:* (`{msg['cumulative_profit']:.8f} "
f"{msg['stake_currency']}{cp_extra}`)\n"
)
message = (
f"{msg['emoji']} *{self._exchange_from_msg(msg)}:* "
f"{'Exited' if is_fill else 'Exiting'} {msg['pair']} (#{msg['trade_id']})\n"
f"{exit_wording} {msg['pair']} (#{msg['trade_id']})\n"
f"{self._add_analyzed_candle(msg['pair'])}"
f"*{f'{profit_prefix}Profit' if is_fill else f'Unrealized {profit_prefix}Profit'}:* "
f"`{msg['profit_ratio']:.2%}{msg['profit_extra']}`\n"
@@ -364,7 +366,7 @@ class Telegram(RPCHandler):
elif msg['type'] == RPCMessageType.EXIT_FILL:
message += f"*Exit Rate:* `{msg['close_rate']:.8f}`"
if msg.get('sub_trade'):
if is_sub_trade:
if self._rpc._fiat_converter:
msg['stake_amount_fiat'] = self._rpc._fiat_converter.convert_amount(
msg['stake_amount'], msg['stake_currency'], msg['fiat_currency'])
@@ -486,7 +488,9 @@ class Telegram(RPCHandler):
if order_nr == 1:
lines.append(f"*{wording} #{order_nr}:*")
lines.append(
f"*Amount:* {cur_entry_amount} ({order['cost']:.8f} {quote_currency})")
f"*Amount:* {cur_entry_amount} "
f"({round_coin_value(order['cost'], quote_currency)})"
)
lines.append(f"*Average Price:* {cur_entry_average}")
else:
sum_stake = 0
@@ -582,7 +586,7 @@ class Telegram(RPCHandler):
if position_adjust:
max_buy_str = (f"/{max_entries + 1}" if (max_entries > 0) else "")
lines.append("*Number of Entries:* `{num_entries}`" + max_buy_str)
lines.append("*Number of Entries:* `{num_entries}" + max_buy_str + "`")
lines.append("*Number of Exits:* `{num_exits}`")
lines.extend([
@@ -597,7 +601,8 @@ class Telegram(RPCHandler):
if r['is_open']:
if r.get('realized_profit'):
lines.append("*Realized Profit:* `{realized_profit_r}`")
lines.append(
"*Realized Profit:* `{realized_profit_r} {realized_profit_ratio:.2%}`")
lines.append("*Total Profit:* `{total_profit_abs_r}` ")
if (r['stop_loss_abs'] != r['initial_stop_loss_abs']