buy notification code consolidation

This commit is contained in:
ethan 2021-11-13 15:46:00 -05:00
parent 0bc9384451
commit c4c1b301cd

View File

@ -219,49 +219,25 @@ class Telegram(RPCHandler):
else: else:
msg['stake_amount_fiat'] = 0 msg['stake_amount_fiat'] = 0
content = [] message = "\N{CHECK MARK} *{exchange}:* Bought {pair} (#{trade_id})\n".format(**msg)
# Buy Order Fill message += "*Buy Tag:* `{buy_tag}`\n".format(**msg) if msg.get('buy_tag', None) else ""
message += "*Amount:* `{amount:.8f}`\n".format(**msg)
if msg['type'] == RPCMessageType.BUY_FILL: if msg['type'] == RPCMessageType.BUY_FILL:
content.append( message += f"*Open Rate:* `{msg['open_rate']:.8f}`\n"
f"\N{CHECK MARK} *{msg['exchange']}:* Bought {msg['pair']}"
f" (#{msg['trade_id']})\n" elif msg['type'] == RPCMessageType.BUY:
) message = message.replace('Bought', 'Buying')\
if msg.get('buy_tag', None): .replace("\N{CHECK MARK}", "\N{LARGE BLUE CIRCLE}")
content.append(f"*Buy Tag:* `{msg['buy_tag']}`\n") message += f"*Open Rate:* `{msg['limit']:.8f}`\n"\
content.append(f"*Amount:* `{msg['amount']:.8f}`\n") f"*Current Rate:* `{msg['current_rate']:.8f}`\n"
content.append(f"*Open Rate:* `{msg['open_rate']:.8f}`\n")
content.append( message += f"*Total:* `({round_coin_value(msg['stake_amount'], msg['stake_currency'])}"
f"*Total:* `({round_coin_value(msg['stake_amount'], msg['stake_currency'])}"
)
if msg.get('fiat_currency', None): if msg.get('fiat_currency', None):
content.append( message += f", {round_coin_value(msg['stake_amount_fiat'], msg['fiat_currency'])}"
f", {round_coin_value(msg['stake_amount_fiat'], msg['fiat_currency'])}"
)
message = ''.join(content)
message += ")`" message += ")`"
# Buy Order Ask
else:
content.append(
f"\N{LARGE BLUE CIRCLE} *{msg['exchange']}:* Buying {msg['pair']}"
f" (#{msg['trade_id']})\n"
)
if msg.get('buy_tag', None):
content.append(f"*Buy Tag:* `{msg['buy_tag']}`\n")
content.append(f"*Amount:* `{msg['amount']:.8f}`\n")
content.append(f"*Open Rate:* `{msg['limit']:.8f}`\n")
content.append(f"*Current Rate:* `{msg['current_rate']:.8f}`\n")
content.append(
f"*Total:* `({round_coin_value(msg['stake_amount'], msg['stake_currency'])}"
)
if msg.get('fiat_currency', None):
content.append(
f", {round_coin_value(msg['stake_amount_fiat'], msg['fiat_currency'])}"
)
message = ''.join(content)
message += ")`"
return message return message
def _format_sell_msg(self, msg: Dict[str, Any]) -> str: def _format_sell_msg(self, msg: Dict[str, Any]) -> str: