telegram message concatenation refactored
This commit is contained in:
parent
d09b33ae93
commit
6045f07a9c
@ -193,21 +193,25 @@ class Telegram(RPC):
|
|||||||
for result in results:
|
for result in results:
|
||||||
result['date'] = result['date'].humanize()
|
result['date'] = result['date'].humanize()
|
||||||
|
|
||||||
messages = [
|
messages = []
|
||||||
"*Trade ID:* `{trade_id}`\n"
|
for r in results:
|
||||||
"*Current Pair:* {pair}\n"
|
lines = [
|
||||||
"*Open Since:* `{date}`\n"
|
"*Trade ID:* `{trade_id}`",
|
||||||
"*Amount:* `{amount}`\n"
|
"*Current Pair:* {pair}",
|
||||||
"*Open Rate:* `{open_rate:.8f}`\n"
|
"*Open Since:* `{date}`",
|
||||||
"*Close Rate:* `{close_rate}`\n"
|
"*Amount:* `{amount}`",
|
||||||
"*Current Rate:* `{current_rate:.8f}`\n"
|
"*Open Rate:* `{open_rate:.8f}`",
|
||||||
"*Close Profit:* `{close_profit}`\n"
|
"*Close Rate:* `{close_rate}`" if r['close_rate'] else "",
|
||||||
"*Current Profit:* `{current_profit:.2f}%`\n"
|
"*Current Rate:* `{current_rate:.8f}`",
|
||||||
"*Open Order:* `{open_order}`".format(**result)
|
"*Close Profit:* `{close_profit}`",
|
||||||
for result in results
|
"*Current Profit:* `{current_profit:.2f}%`",
|
||||||
]
|
"*Open Order:* `{open_order}`"
|
||||||
|
]
|
||||||
|
messages.append("\n".join(filter(None,lines)).format(**r))
|
||||||
|
|
||||||
for msg in messages:
|
for msg in messages:
|
||||||
self._send_msg(msg, bot=bot)
|
self._send_msg(msg, bot=bot)
|
||||||
|
|
||||||
except RPCException as e:
|
except RPCException as e:
|
||||||
self._send_msg(str(e), bot=bot)
|
self._send_msg(str(e), bot=bot)
|
||||||
|
|
||||||
|
@ -267,6 +267,12 @@ def test_status_handle(default_conf, update, ticker, fee, markets, mocker) -> No
|
|||||||
# Trigger status while we have a fulfilled order for the open trade
|
# Trigger status while we have a fulfilled order for the open trade
|
||||||
telegram._status(bot=MagicMock(), update=update)
|
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 msg_mock.call_count == 1
|
assert msg_mock.call_count == 1
|
||||||
assert 'ETH/BTC' in msg_mock.call_args_list[0][0][0]
|
assert 'ETH/BTC' in msg_mock.call_args_list[0][0][0]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user