mirror of
https://github.com/freqtrade/freqtrade.git
synced 2026-01-20 05:50:36 +00:00
refactor: don't do delayed formatting on status message
This commit is contained in:
@@ -774,26 +774,25 @@ class Telegram(RPCHandler):
|
|||||||
r["realized_profit_r"] = fmt_coin(r["realized_profit"], r["quote_currency"])
|
r["realized_profit_r"] = fmt_coin(r["realized_profit"], r["quote_currency"])
|
||||||
r["total_profit_abs_r"] = fmt_coin(r["total_profit_abs"], r["quote_currency"])
|
r["total_profit_abs_r"] = fmt_coin(r["total_profit_abs"], r["quote_currency"])
|
||||||
lines = [
|
lines = [
|
||||||
"*Trade ID:* `{trade_id}`" + (" `(since {open_date_hum})`" if r["is_open"] else ""),
|
f"*Trade ID:* `{r['trade_id']}`"
|
||||||
"*Current Pair:* {pair}",
|
+ (f" `(since {r['open_date_hum']})`" if r["is_open"] else ""),
|
||||||
|
f"*Current Pair:* {r['pair']}",
|
||||||
(
|
(
|
||||||
f"*Direction:* {'`Short`' if r.get('is_short') else '`Long`'}"
|
f"*Direction:* {'`Short`' if r.get('is_short') else '`Long`'}"
|
||||||
+ " ` ({leverage}x)`"
|
+ (f" ` ({r['leverage']}x)`" if r.get("leverage") else "")
|
||||||
if r.get("leverage")
|
|
||||||
else ""
|
|
||||||
),
|
),
|
||||||
"*Amount:* `{amount} ({stake_amount_r})`",
|
f"*Amount:* `{r['amount']} ({r['stake_amount_r']})`",
|
||||||
"*Total invested:* `{max_stake_amount_r}`" if position_adjust else "",
|
f"*Total invested:* `{r['max_stake_amount_r']}`" if position_adjust else "",
|
||||||
"*Enter Tag:* `{enter_tag}`" if r["enter_tag"] else "",
|
f"*Enter Tag:* `{r['enter_tag']}`" if r["enter_tag"] else "",
|
||||||
"*Exit Reason:* `{exit_reason}`" if r["exit_reason"] else "",
|
f"*Exit Reason:* `{r['exit_reason']}`" if r["exit_reason"] else "",
|
||||||
]
|
]
|
||||||
|
|
||||||
if position_adjust:
|
if position_adjust:
|
||||||
max_buy_str = f"/{max_entries + 1}" if (max_entries > 0) else ""
|
max_buy_str = f"/{max_entries + 1}" if (max_entries > 0) else ""
|
||||||
lines.extend(
|
lines.extend(
|
||||||
[
|
[
|
||||||
"*Number of Entries:* `{num_entries}" + max_buy_str + "`",
|
f"*Number of Entries:* `{r['num_entries']}{max_buy_str}`",
|
||||||
"*Number of Exits:* `{num_exits}`",
|
f"*Number of Exits:* `{r['num_exits']}`",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -801,15 +800,15 @@ class Telegram(RPCHandler):
|
|||||||
[
|
[
|
||||||
f"*Open Rate:* `{round_value(r['open_rate'], 8)}`",
|
f"*Open Rate:* `{round_value(r['open_rate'], 8)}`",
|
||||||
f"*Close Rate:* `{round_value(r['close_rate'], 8)}`" if r["close_rate"] else "",
|
f"*Close Rate:* `{round_value(r['close_rate'], 8)}`" if r["close_rate"] else "",
|
||||||
"*Open Date:* `{open_date}`",
|
f"*Open Date:* `{r['open_date']}`",
|
||||||
"*Close Date:* `{close_date}`" if r["close_date"] else "",
|
f"*Close Date:* `{r['close_date']}`" if r["close_date"] else "",
|
||||||
(
|
(
|
||||||
f" \n*Current Rate:* `{round_value(r['current_rate'], 8)}`"
|
f" \n*Current Rate:* `{round_value(r['current_rate'], 8)}`"
|
||||||
if r["is_open"]
|
if r["is_open"]
|
||||||
else ""
|
else ""
|
||||||
),
|
),
|
||||||
("*Unrealized Profit:* " if r["is_open"] else "*Close Profit: *")
|
("*Unrealized Profit:* " if r["is_open"] else "*Close Profit: *")
|
||||||
+ "`{profit_ratio:.2%}` `({profit_abs_r})`",
|
+ f"`{r['profit_ratio']:.2%}` `({r['profit_abs_r']})`",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -817,9 +816,9 @@ class Telegram(RPCHandler):
|
|||||||
if r.get("realized_profit"):
|
if r.get("realized_profit"):
|
||||||
lines.extend(
|
lines.extend(
|
||||||
[
|
[
|
||||||
"*Realized Profit:* `{realized_profit_ratio:.2%} "
|
f"*Realized Profit:* `{r['realized_profit_ratio']:.2%} "
|
||||||
"({realized_profit_r})`",
|
f"({r['realized_profit_r']})`",
|
||||||
"*Total Profit:* `{total_profit_ratio:.2%} ({total_profit_abs_r})`",
|
f"*Total Profit:* `{r['total_profit_ratio']:.2%} ({r['total_profit_abs_r']})`",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -835,23 +834,23 @@ class Telegram(RPCHandler):
|
|||||||
):
|
):
|
||||||
# Adding initial stoploss only if it is different from stoploss
|
# Adding initial stoploss only if it is different from stoploss
|
||||||
lines.append(
|
lines.append(
|
||||||
"*Initial Stoploss:* `{initial_stop_loss_abs:.8f}` "
|
f"*Initial Stoploss:* `{r['initial_stop_loss_abs']:.8f}` "
|
||||||
"`({initial_stop_loss_ratio:.2%})`"
|
f"`({r['initial_stop_loss_ratio']:.2%})`"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Adding stoploss and stoploss percentage only if it is not None
|
# Adding stoploss and stoploss percentage only if it is not None
|
||||||
lines.append(
|
lines.append(
|
||||||
f"*Stoploss:* `{round_value(r['stop_loss_abs'], 8)}` "
|
f"*Stoploss:* `{round_value(r['stop_loss_abs'], 8)}` "
|
||||||
+ ("`({stop_loss_ratio:.2%})`" if r["stop_loss_ratio"] else "")
|
+ (f"`({r['stop_loss_ratio']:.2%})`" if r["stop_loss_ratio"] else "")
|
||||||
)
|
)
|
||||||
lines.append(
|
lines.append(
|
||||||
f"*Stoploss distance:* `{round_value(r['stoploss_current_dist'], 8)}` "
|
f"*Stoploss distance:* `{round_value(r['stoploss_current_dist'], 8)}` "
|
||||||
"`({stoploss_current_dist_ratio:.2%})`"
|
f"`({r['stoploss_current_dist_ratio']:.2%})`"
|
||||||
)
|
)
|
||||||
if r.get("open_orders"):
|
if open_orders := r.get("open_orders"):
|
||||||
lines.append(
|
lines.append(
|
||||||
"*Open Order:* `{open_orders}`"
|
f"*Open Order:* `{open_orders}`"
|
||||||
+ ("- `{exit_order_status}`" if r["exit_order_status"] else "")
|
+ (f"- `{r['exit_order_status']}`" if r["exit_order_status"] else "")
|
||||||
)
|
)
|
||||||
|
|
||||||
await self.__send_status_msg(lines, r)
|
await self.__send_status_msg(lines, r)
|
||||||
@@ -867,10 +866,10 @@ class Telegram(RPCHandler):
|
|||||||
if (len(msg) + len(line) + 1) < MAX_MESSAGE_LENGTH:
|
if (len(msg) + len(line) + 1) < MAX_MESSAGE_LENGTH:
|
||||||
msg += line + "\n"
|
msg += line + "\n"
|
||||||
else:
|
else:
|
||||||
await self._send_msg(msg.format(**r))
|
await self._send_msg(msg)
|
||||||
msg = "*Trade ID:* `{trade_id}` - continued\n" + line + "\n"
|
msg = f"*Trade ID:* `{r['trade_id']}` - continued\n" + line + "\n"
|
||||||
|
|
||||||
await self._send_msg(msg.format(**r))
|
await self._send_msg(msg)
|
||||||
|
|
||||||
@authorized_only
|
@authorized_only
|
||||||
async def _status_table(self, update: Update, context: CallbackContext) -> None:
|
async def _status_table(self, update: Update, context: CallbackContext) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user