From 375e671aafc508e91c0ab4fd9b33f74d2eba7400 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 18 Aug 2020 20:12:14 +0200 Subject: [PATCH 1/2] Move formatting of /daily to telegram so /daily can return numbers in the API --- freqtrade/rpc/rpc.py | 10 ++++------ freqtrade/rpc/telegram.py | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index f4e20c16f..7be49b948 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -224,22 +224,20 @@ class RPC: ]).order_by(Trade.close_date).all() curdayprofit = sum(trade.close_profit_abs for trade in trades) profit_days[profitday] = { - 'amount': f'{curdayprofit:.8f}', + 'amount': curdayprofit, 'trades': len(trades) } data = [ { 'date': key, - 'abs_profit': f'{float(value["amount"]):.8f}', - 'fiat_value': '{value:.3f}'.format( - value=self._fiat_converter.convert_amount( + 'abs_profit': value["amount"], + 'fiat_value': self._fiat_converter.convert_amount( value['amount'], stake_currency, fiat_display_currency ) if self._fiat_converter else 0, - ), - 'trade_count': f'{value["trades"]}', + 'trade_count': value["trades"], } for key, value in profit_days.items() ] diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index f1d3cde21..809deb765 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -305,8 +305,8 @@ class Telegram(RPC): ) stats_tab = tabulate( [[day['date'], - f"{day['abs_profit']} {stats['stake_currency']}", - f"{day['fiat_value']} {stats['fiat_display_currency']}", + f"{day['abs_profit']:.8f} {stats['stake_currency']}", + f"{day['fiat_value']:.3f} {stats['fiat_display_currency']}", f"{day['trade_count']} trades"] for day in stats['data']], headers=[ 'Day', From e206cc9c216bbf7f140797c001692f41c0d7fd48 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 18 Aug 2020 20:15:41 +0200 Subject: [PATCH 2/2] Adjust tests --- tests/rpc/test_rpc.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index 9bbd34672..164c825ba 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -255,11 +255,11 @@ def test_rpc_daily_profit(default_conf, update, ticker, fee, assert days['fiat_display_currency'] == default_conf['fiat_display_currency'] for day in days['data']: # [datetime.date(2018, 1, 11), '0.00000000 BTC', '0.000 USD'] - assert (day['abs_profit'] == '0.00000000' or - day['abs_profit'] == '0.00006217') + assert (day['abs_profit'] == 0.0 or + day['abs_profit'] == 0.00006217) - assert (day['fiat_value'] == '0.000' or - day['fiat_value'] == '0.767') + assert (day['fiat_value'] == 0.0 or + day['fiat_value'] == 0.76748865) # ensure first day is current date assert str(days['data'][0]['date']) == str(datetime.utcnow().date())