use more granular msg dict for buy/sell notifications
This commit is contained in:
@@ -12,7 +12,7 @@ from telegram.error import NetworkError, TelegramError
|
||||
from telegram.ext import CommandHandler, Updater
|
||||
|
||||
from freqtrade.__init__ import __version__
|
||||
from freqtrade.rpc.rpc import RPC, RPCException
|
||||
from freqtrade.rpc import RPC, RPCException, RPCMessageType
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -110,9 +110,42 @@ class Telegram(RPC):
|
||||
"""
|
||||
self._updater.stop()
|
||||
|
||||
def send_msg(self, msg: Dict[str, str]) -> None:
|
||||
def send_msg(self, msg: Dict[str, Any]) -> None:
|
||||
""" Send a message to telegram channel """
|
||||
self._send_msg('*Status:* `{status}`'.format(**msg))
|
||||
|
||||
if msg['type'] == RPCMessageType.BUY_NOTIFICATION:
|
||||
message = "*{exchange}:* Buying [{pair}]({market_url})\n" \
|
||||
"with limit `{limit:.8f}\n" \
|
||||
"({stake_amount:.6f} {stake_currency}," \
|
||||
"{stake_amount_fiat:.3f} {fiat_currency})`" \
|
||||
.format(**msg)
|
||||
|
||||
elif msg['type'] == RPCMessageType.SELL_NOTIFICATION:
|
||||
msg['amount'] = round(msg['amount'], 8)
|
||||
msg['profit_percent'] = round(msg['profit_percent'] * 100, 2)
|
||||
|
||||
message = "*{exchange}:* Selling [{pair}]({market_url})\n" \
|
||||
"*Limit:* `{limit:.8f}`\n" \
|
||||
"*Amount:* `{amount:.8f}`\n" \
|
||||
"*Open Rate:* `{open_rate:.8f}`\n" \
|
||||
"*Current Rate:* `{current_rate:.8f}`\n" \
|
||||
"*Profit:* `{profit_percent:.2f}%`".format(**msg)
|
||||
|
||||
# Check if all sell properties are available.
|
||||
# This might not be the case if the message origin is triggered by /forcesell
|
||||
if all(prop in msg for prop in ['gain', 'profit_fiat',
|
||||
'fiat_currency', 'stake_currency']):
|
||||
message += '` ({gain}: {profit_amount:.8f} {stake_currency}`' \
|
||||
'` / {profit_fiat:.3f} {fiat_currency})`'.format(**msg)
|
||||
|
||||
self._send_msg(message)
|
||||
elif msg['type'] == RPCMessageType.STATUS_NOTIFICATION:
|
||||
message = '*Status:* `{status}`'.format(**msg)
|
||||
|
||||
else:
|
||||
raise NotImplementedError('Unknown message type: {}'.format(msg['type']))
|
||||
|
||||
self._send_msg(message)
|
||||
|
||||
@authorized_only
|
||||
def _status(self, bot: Bot, update: Update) -> None:
|
||||
|
Reference in New Issue
Block a user