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),
|
amount=round(trade.amount, 8),
|
||||||
close_profit=fmt_close_profit,
|
close_profit=fmt_close_profit,
|
||||||
current_profit=round(current_profit * 100, 2),
|
current_profit=round(current_profit * 100, 2),
|
||||||
|
stop_loss=trade.stop_loss,
|
||||||
open_order='({} {} rem={:.8f})'.format(
|
open_order='({} {} rem={:.8f})'.format(
|
||||||
order['type'], order['side'], order['remaining']
|
order['type'], order['side'], order['remaining']
|
||||||
) if order else None,
|
) if order else None,
|
||||||
|
@ -194,21 +194,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}` (since `{date}`)",
|
||||||
"*Amount:* `{amount}`\n"
|
"*Current Pair:* {pair}",
|
||||||
"*Open Rate:* `{open_rate:.8f}`\n"
|
"*Amount:* `{amount}`",
|
||||||
"*Close Rate:* `{close_rate}`\n"
|
"*Open Rate:* `{open_rate:.8f}`",
|
||||||
"*Current Rate:* `{current_rate:.8f}`\n"
|
"*Close Rate:* `{close_rate}`" if r['close_rate'] else "",
|
||||||
"*Close Profit:* `{close_profit}`\n"
|
"*Current Rate:* `{current_rate:.8f}`",
|
||||||
"*Current Profit:* `{current_profit:.2f}%`\n"
|
"*Close Profit:* `{close_profit}`" if r['close_profit'] else "",
|
||||||
"*Open Order:* `{open_order}`".format(**result)
|
"*Current Profit:* `{current_profit:.2f}%`",
|
||||||
for result in results
|
"*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:
|
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)
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, markets, mocker) -> None:
|
|||||||
'amount': 90.99181074,
|
'amount': 90.99181074,
|
||||||
'close_profit': None,
|
'close_profit': None,
|
||||||
'current_profit': -0.59,
|
'current_profit': -0.59,
|
||||||
|
'stop_loss': 0.0,
|
||||||
'open_order': '(limit buy rem=0.00000000)'
|
'open_order': '(limit buy rem=0.00000000)'
|
||||||
} == results[0]
|
} == results[0]
|
||||||
|
|
||||||
@ -79,6 +80,7 @@ def test_rpc_trade_status(default_conf, ticker, fee, markets, mocker) -> None:
|
|||||||
'amount': 90.99181074,
|
'amount': 90.99181074,
|
||||||
'close_profit': None,
|
'close_profit': None,
|
||||||
'current_profit': ANY,
|
'current_profit': ANY,
|
||||||
|
'stop_loss': 0.0,
|
||||||
'open_order': '(limit buy rem=0.00000000)'
|
'open_order': '(limit buy rem=0.00000000)'
|
||||||
} == results[0]
|
} == results[0]
|
||||||
|
|
||||||
|
@ -201,6 +201,7 @@ def test_status(default_conf, update, mocker, fee, ticker, markets) -> None:
|
|||||||
'amount': 90.99181074,
|
'amount': 90.99181074,
|
||||||
'close_profit': None,
|
'close_profit': None,
|
||||||
'current_profit': -0.59,
|
'current_profit': -0.59,
|
||||||
|
'stop_loss': 1.099e-05,
|
||||||
'open_order': '(limit buy rem=0.00000000)'
|
'open_order': '(limit buy rem=0.00000000)'
|
||||||
}]),
|
}]),
|
||||||
_status_table=status_table,
|
_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
|
# 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 'Close Profit' 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