Merge pull request #1707 from mishaker/telegram_msg
Telegram status message refactoring
This commit is contained in:
commit
b4472a165e
@ -110,6 +110,7 @@ class RPC(object):
|
||||
amount=round(trade.amount, 8),
|
||||
close_profit=fmt_close_profit,
|
||||
current_profit=round(current_profit * 100, 2),
|
||||
stop_loss=trade.stop_loss,
|
||||
open_order='({} {} rem={:.8f})'.format(
|
||||
order['type'], order['side'], order['remaining']
|
||||
) if order else None,
|
||||
|
@ -194,21 +194,25 @@ class Telegram(RPC):
|
||||
for result in results:
|
||||
result['date'] = result['date'].humanize()
|
||||
|
||||
messages = [
|
||||
"*Trade ID:* `{trade_id}`\n"
|
||||
"*Current Pair:* {pair}\n"
|
||||
"*Open Since:* `{date}`\n"
|
||||
"*Amount:* `{amount}`\n"
|
||||
"*Open Rate:* `{open_rate:.8f}`\n"
|
||||
"*Close Rate:* `{close_rate}`\n"
|
||||
"*Current Rate:* `{current_rate:.8f}`\n"
|
||||
"*Close Profit:* `{close_profit}`\n"
|
||||
"*Current Profit:* `{current_profit:.2f}%`\n"
|
||||
"*Open Order:* `{open_order}`".format(**result)
|
||||
for result in results
|
||||
]
|
||||
messages = []
|
||||
for r in results:
|
||||
lines = [
|
||||
"*Trade ID:* `{trade_id}` (since `{date}`)",
|
||||
"*Current Pair:* {pair}",
|
||||
"*Amount:* `{amount}`",
|
||||
"*Open Rate:* `{open_rate:.8f}`",
|
||||
"*Close Rate:* `{close_rate}`" if r['close_rate'] else "",
|
||||
"*Current Rate:* `{current_rate:.8f}`",
|
||||
"*Close Profit:* `{close_profit}`" if r['close_profit'] else "",
|
||||
"*Current Profit:* `{current_profit:.2f}%`",
|
||||
"*Stoploss:* `{stop_loss:.8f}`",
|
||||
"*Open Order:* `{open_order}`" if r['open_order'] else "",
|
||||
]
|
||||
messages.append("\n".join(filter(None, lines)).format(**r))
|
||||
|
||||
for msg in messages:
|
||||
self._send_msg(msg, bot=bot)
|
||||
|
||||
except RPCException as e:
|
||||
self._send_msg(str(e), bot=bot)
|
||||
|
||||
|
@ -59,6 +59,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, markets, mocker) -> None:
|
||||
'amount': 90.99181074,
|
||||
'close_profit': None,
|
||||
'current_profit': -0.59,
|
||||
'stop_loss': 0.0,
|
||||
'open_order': '(limit buy rem=0.00000000)'
|
||||
} == results[0]
|
||||
|
||||
@ -79,6 +80,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, markets, mocker) -> None:
|
||||
'amount': 90.99181074,
|
||||
'close_profit': None,
|
||||
'current_profit': ANY,
|
||||
'stop_loss': 0.0,
|
||||
'open_order': '(limit buy rem=0.00000000)'
|
||||
} == results[0]
|
||||
|
||||
|
@ -201,6 +201,7 @@ def test_status(default_conf, update, mocker, fee, ticker, markets) -> None:
|
||||
'amount': 90.99181074,
|
||||
'close_profit': None,
|
||||
'current_profit': -0.59,
|
||||
'stop_loss': 1.099e-05,
|
||||
'open_order': '(limit buy rem=0.00000000)'
|
||||
}]),
|
||||
_status_table=status_table,
|
||||
@ -267,6 +268,13 @@ def test_status_handle(default_conf, update, ticker, fee, markets, mocker) -> No
|
||||
# Trigger status while we have a fulfilled order for the open trade
|
||||
telegram._status(bot=MagicMock(), update=update)
|
||||
|
||||
# close_rate should not be included in the message as the trade is not closed
|
||||
# and no line should be empty
|
||||
lines = msg_mock.call_args_list[0][0][0].split('\n')
|
||||
assert '' not in lines
|
||||
assert 'Close Rate' not in ''.join(lines)
|
||||
assert 'Close Profit' not in ''.join(lines)
|
||||
|
||||
assert msg_mock.call_count == 1
|
||||
assert 'ETH/BTC' in msg_mock.call_args_list[0][0][0]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user