From 10ef0f54ac7847e34fc4f096a50b63144bafb42e Mon Sep 17 00:00:00 2001 From: Eugene Schava Date: Mon, 17 May 2021 11:12:11 +0300 Subject: [PATCH] Total row for telegram "/status table" command --- freqtrade/rpc/telegram.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 2e288ee33..157a2b9a5 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -5,6 +5,7 @@ This module manage Telegram communication """ import json import logging +import re from datetime import timedelta from html import escape from itertools import chain @@ -354,19 +355,33 @@ class Telegram(RPCHandler): :return: None """ try: + fiat_currency = self._config.get('fiat_display_currency', '') statlist, head = self._rpc._rpc_status_table( - self._config['stake_currency'], self._config.get('fiat_display_currency', '')) + self._config['stake_currency'], fiat_currency) + show_total = fiat_currency != '' + total_sum = 0 + if show_total: + total_sum = sum(map(lambda m: float(m[1]) if m else 0, map(lambda trade: re.compile(".*\((-?\d*\.\d*)\)").match(trade[-1]), statlist))) max_trades_per_msg = 50 """ Calculate the number of messages of 50 trades per message 0.99 is used to make sure that there are no extra (empty) messages As an example with 50 trades, there will be int(50/50 + 0.99) = 1 message """ - for i in range(0, max(int(len(statlist) / max_trades_per_msg + 0.99), 1)): + messages_count = max(int(len(statlist) / max_trades_per_msg + 0.99), 1) + for i in range(0, messages_count): + if show_total and i == messages_count - 1: + # append total line + trades.append(["Total", "", "", f"{total_sum:.2f} {fiat_currency}"]) + message = tabulate(statlist[i * max_trades_per_msg:(i + 1) * max_trades_per_msg], headers=head, tablefmt='simple') + if show_total and i == messages_count - 1: + # insert separators line between Total + lines = message.split("\n") + message = "\n".join(lines[:-1] + [lines[1]] + [lines[-1]]) self._send_msg(f"
{message}
", parse_mode=ParseMode.HTML) except RPCException as e: self._send_msg(str(e))