Improve /status message (show Total profit)

This commit is contained in:
Matthias 2023-02-28 19:54:47 +01:00
parent 2f1c5cf143
commit 386915378b
5 changed files with 27 additions and 7 deletions

View File

@ -243,7 +243,7 @@ Enter Tag is configurable via Strategy.
> **Enter Tag:** Awesome Long Signal > **Enter Tag:** Awesome Long Signal
> **Open Rate:** `0.00007489` > **Open Rate:** `0.00007489`
> **Current Rate:** `0.00007489` > **Current Rate:** `0.00007489`
> **Current Profit:** `12.95%` > **Unrealized Profit:** `12.95%`
> **Stoploss:** `0.00007389 (-0.02%)` > **Stoploss:** `0.00007389 (-0.02%)`
### /status table ### /status table

View File

@ -169,6 +169,7 @@ class RPC:
for trade in trades: for trade in trades:
order: Optional[Order] = None order: Optional[Order] = None
current_profit_fiat: Optional[float] = None current_profit_fiat: Optional[float] = None
combined_profit_fiat: Optional[float] = None
if trade.open_order_id: if trade.open_order_id:
order = trade.select_order_by_order_id(trade.open_order_id) order = trade.select_order_by_order_id(trade.open_order_id)
# calculate profit and send message to user # calculate profit and send message to user
@ -190,6 +191,7 @@ class RPC:
current_rate = trade.close_rate current_rate = trade.close_rate
current_profit = trade.close_profit current_profit = trade.close_profit
current_profit_abs = trade.close_profit_abs current_profit_abs = trade.close_profit_abs
combined_profit_abs = trade.realized_profit + current_profit_abs
# Calculate fiat profit # Calculate fiat profit
if not isnan(current_profit_abs) and self._fiat_converter: if not isnan(current_profit_abs) and self._fiat_converter:
@ -198,6 +200,11 @@ class RPC:
self._freqtrade.config['stake_currency'], self._freqtrade.config['stake_currency'],
self._freqtrade.config['fiat_display_currency'] self._freqtrade.config['fiat_display_currency']
) )
combined_profit_fiat = self._fiat_converter.convert_amount(
combined_profit_abs,
self._freqtrade.config['stake_currency'],
self._freqtrade.config['fiat_display_currency']
)
# Calculate guaranteed profit (in case of trailing stop) # Calculate guaranteed profit (in case of trailing stop)
stoploss_entry_dist = trade.calc_profit(trade.stop_loss) stoploss_entry_dist = trade.calc_profit(trade.stop_loss)
@ -215,6 +222,8 @@ class RPC:
profit_abs=current_profit_abs, profit_abs=current_profit_abs,
profit_fiat=current_profit_fiat, profit_fiat=current_profit_fiat,
combined_profit_abs=combined_profit_abs,
combined_profit_fiat=combined_profit_fiat,
stoploss_current_dist=stoploss_current_dist, stoploss_current_dist=stoploss_current_dist,
stoploss_current_dist_ratio=round(stoploss_current_dist_ratio, 8), stoploss_current_dist_ratio=round(stoploss_current_dist_ratio, 8),
stoploss_current_dist_pct=round(stoploss_current_dist_ratio * 100, 2), stoploss_current_dist_pct=round(stoploss_current_dist_ratio * 100, 2),

View File

@ -562,15 +562,18 @@ class Telegram(RPCHandler):
r['open_date_hum'] = arrow.get(r['open_date']).humanize() r['open_date_hum'] = arrow.get(r['open_date']).humanize()
r['num_entries'] = len([o for o in r['orders'] if o['ft_is_entry']]) r['num_entries'] = len([o for o in r['orders'] if o['ft_is_entry']])
r['exit_reason'] = r.get('exit_reason', "") r['exit_reason'] = r.get('exit_reason', "")
r['rounded_stake_amount'] = round_coin_value(r['stake_amount'], r['quote_currency']) r['stake_amount_r'] = round_coin_value(r['stake_amount'], r['quote_currency'])
r['rounded_profit_abs'] = round_coin_value(r['profit_abs'], r['quote_currency']) r['profit_abs_r'] = round_coin_value(r['profit_abs'], r['quote_currency'])
r['realized_profit_r'] = round_coin_value(r['realized_profit'], r['quote_currency'])
r['combined_profit_abs_r'] = round_coin_value(
r['combined_profit_abs'], r['quote_currency'])
lines = [ lines = [
"*Trade ID:* `{trade_id}`" + "*Trade ID:* `{trade_id}`" +
(" `(since {open_date_hum})`" if r['is_open'] else ""), (" `(since {open_date_hum})`" if r['is_open'] else ""),
"*Current Pair:* {pair}", "*Current Pair:* {pair}",
"*Direction:* " + ("`Short`" if r.get('is_short') else "`Long`"), "*Direction:* " + ("`Short`" if r.get('is_short') else "`Long`"),
"*Leverage:* `{leverage}`" if r.get('leverage') else "", "*Leverage:* `{leverage}`" if r.get('leverage') else "",
"*Amount:* `{amount} ({rounded_stake_amount})`", "*Amount:* `{amount} ({stake_amount_r})`",
"*Enter Tag:* `{enter_tag}`" if r['enter_tag'] else "", "*Enter Tag:* `{enter_tag}`" if r['enter_tag'] else "",
"*Exit Reason:* `{exit_reason}`" if r['exit_reason'] else "", "*Exit Reason:* `{exit_reason}`" if r['exit_reason'] else "",
] ]
@ -585,13 +588,15 @@ class Telegram(RPCHandler):
"*Open Date:* `{open_date}`", "*Open Date:* `{open_date}`",
"*Close Date:* `{close_date}`" if r['close_date'] else "", "*Close Date:* `{close_date}`" if r['close_date'] else "",
"*Current Rate:* `{current_rate:.8f}`" if r['is_open'] else "", "*Current Rate:* `{current_rate:.8f}`" if r['is_open'] else "",
("*Current Profit:* " if r['is_open'] else "*Close Profit: *") ("*Unrealized Profit:* " if r['is_open'] else "*Close Profit: *")
+ "`{profit_ratio:.2%}` `({rounded_profit_abs})`", + "`{profit_ratio:.2%}` `({profit_abs_r})`",
]) ])
if r['is_open']: if r['is_open']:
if r.get('realized_profit'): if r.get('realized_profit'):
lines.append("*Realized Profit:* `{realized_profit:.8f}`") lines.append("*Realized Profit:* `{realized_profit_r}`")
lines.append("*Total Profit:* `{combined_profit_abs_r}` ")
if (r['stop_loss_abs'] != r['initial_stop_loss_abs'] if (r['stop_loss_abs'] != r['initial_stop_loss_abs']
and r['initial_stop_loss_ratio'] is not None): and r['initial_stop_loss_ratio'] is not None):
# Adding initial stoploss only if it is different from stoploss # Adding initial stoploss only if it is different from stoploss

View File

@ -76,6 +76,8 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
'stoploss_entry_dist_ratio': -0.10376381, 'stoploss_entry_dist_ratio': -0.10376381,
'open_order': None, 'open_order': None,
'realized_profit': 0.0, 'realized_profit': 0.0,
'combined_profit_abs': -4.09e-06,
'combined_profit_fiat': ANY,
'exchange': 'binance', 'exchange': 'binance',
'leverage': 1.0, 'leverage': 1.0,
'interest_rate': 0.0, 'interest_rate': 0.0,
@ -119,6 +121,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
'profit_ratio': 0.0, 'profit_ratio': 0.0,
'profit_pct': 0.0, 'profit_pct': 0.0,
'profit_abs': 0.0, 'profit_abs': 0.0,
'combined_profit_abs': 0.0,
'stop_loss_abs': 0.0, 'stop_loss_abs': 0.0,
'stop_loss_pct': None, 'stop_loss_pct': None,
'stop_loss_ratio': None, 'stop_loss_ratio': None,
@ -180,6 +183,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, mocker) -> None:
'profit_ratio': ANY, 'profit_ratio': ANY,
'profit_pct': ANY, 'profit_pct': ANY,
'profit_abs': ANY, 'profit_abs': ANY,
'combined_profit_abs': ANY,
'current_rate': ANY, 'current_rate': ANY,
}) })
assert results[0] == response_norate assert results[0] == response_norate

View File

@ -204,6 +204,8 @@ def test_telegram_status(default_conf, update, mocker) -> None:
'profit': -0.0059, 'profit': -0.0059,
'profit_ratio': -0.0059, 'profit_ratio': -0.0059,
'profit_abs': -0.225, 'profit_abs': -0.225,
'realized_profit': 0.0,
'combined_profit_abs': -0.225,
'initial_stop_loss_abs': 1.098e-05, 'initial_stop_loss_abs': 1.098e-05,
'stop_loss_abs': 1.099e-05, 'stop_loss_abs': 1.099e-05,
'exit_order_status': None, 'exit_order_status': None,