From 6b2a38ccfb9aa3802e6ecc0061d6ee7f09110784 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 15 May 2021 19:39:46 +0200 Subject: [PATCH 1/2] Add absolute Profit to apiserver --- freqtrade/persistence/models.py | 8 +++++--- freqtrade/rpc/api_server/api_schemas.py | 1 + tests/rpc/test_rpc_apiserver.py | 9 ++++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/freqtrade/persistence/models.py b/freqtrade/persistence/models.py index afd51366a..8d2c9d1d3 100644 --- a/freqtrade/persistence/models.py +++ b/freqtrade/persistence/models.py @@ -815,18 +815,20 @@ class Trade(_DECL_BASE, LocalTrade): pair_rates = Trade.query.with_entities( Trade.pair, func.sum(Trade.close_profit).label('profit_sum'), + func.sum(Trade.close_profit_abs).label('profit_sum_abs'), func.count(Trade.pair).label('count') ).filter(Trade.is_open.is_(False))\ .group_by(Trade.pair) \ - .order_by(desc('profit_sum')) \ + .order_by(desc('profit_sum_abs')) \ .all() return [ { 'pair': pair, - 'profit': rate, + 'profit': profit, + 'profit_abs': profit_abs, 'count': count } - for pair, rate, count in pair_rates + for pair, profit, profit_abs, count in pair_rates ] @staticmethod diff --git a/freqtrade/rpc/api_server/api_schemas.py b/freqtrade/rpc/api_server/api_schemas.py index c324f8828..4d06d3ecf 100644 --- a/freqtrade/rpc/api_server/api_schemas.py +++ b/freqtrade/rpc/api_server/api_schemas.py @@ -57,6 +57,7 @@ class Count(BaseModel): class PerformanceEntry(BaseModel): pair: str profit: float + profit_abs: float count: int diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index fc0dee14b..1a66b2e81 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -710,7 +710,7 @@ def test_api_stats(botclient, mocker, ticker, fee, markets,): assert 'draws' in rc.json()['durations'] -def test_api_performance(botclient, mocker, ticker, fee): +def test_api_performance(botclient, fee): ftbot, client = botclient patch_get_signal(ftbot, (True, False)) @@ -728,6 +728,7 @@ def test_api_performance(botclient, mocker, ticker, fee): ) trade.close_profit = trade.calc_profit_ratio() + trade.close_profit_abs = trade.calc_profit() Trade.query.session.add(trade) trade = Trade( @@ -743,14 +744,16 @@ def test_api_performance(botclient, mocker, ticker, fee): close_rate=0.391 ) trade.close_profit = trade.calc_profit_ratio() + trade.close_profit_abs = trade.calc_profit() + Trade.query.session.add(trade) Trade.query.session.flush() rc = client_get(client, f"{BASE_URI}/performance") assert_response(rc) assert len(rc.json()) == 2 - assert rc.json() == [{'count': 1, 'pair': 'LTC/ETH', 'profit': 7.61}, - {'count': 1, 'pair': 'XRP/ETH', 'profit': -5.57}] + assert rc.json() == [{'count': 1, 'pair': 'LTC/ETH', 'profit': 7.61, 'profit_abs': 0.01872279}, + {'count': 1, 'pair': 'XRP/ETH', 'profit': -5.57, 'profit_abs': -0.1150375}] def test_api_status(botclient, mocker, ticker, fee, markets): From 2d7735ba048f1eb18a2301e9824432633721d32e Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 15 May 2021 19:49:21 +0200 Subject: [PATCH 2/2] Update telegram to sort performance by absolute performance --- docs/telegram-usage.md | 10 +++++----- freqtrade/rpc/telegram.py | 7 +++++-- tests/rpc/test_rpc_telegram.py | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/docs/telegram-usage.md b/docs/telegram-usage.md index 824cb17c7..07f5fe7dd 100644 --- a/docs/telegram-usage.md +++ b/docs/telegram-usage.md @@ -262,11 +262,11 @@ Note that for this to work, `forcebuy_enable` needs to be set to true. Return the performance of each crypto-currency the bot has sold. > Performance: -> 1. `RCN/BTC 57.77%` -> 2. `PAY/BTC 56.91%` -> 3. `VIB/BTC 47.07%` -> 4. `SALT/BTC 30.24%` -> 5. `STORJ/BTC 27.24%` +> 1. `RCN/BTC 0.003 BTC (57.77%) (1)` +> 2. `PAY/BTC 0.0012 BTC (56.91%) (1)` +> 3. `VIB/BTC 0.0011 BTC (47.07%) (1)` +> 4. `SALT/BTC 0.0010 BTC (30.24%) (1)` +> 5. `STORJ/BTC 0.0009 BTC (27.24%) (1)` > ... ### /balance diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 8aa96f7b1..2e288ee33 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -711,8 +711,11 @@ class Telegram(RPCHandler): trades = self._rpc._rpc_performance() output = "Performance:\n" for i, trade in enumerate(trades): - stat_line = (f"{i+1}.\t {trade['pair']}\t{trade['profit']:.2f}% " - f"({trade['count']})\n") + stat_line = ( + f"{i+1}.\t {trade['pair']}\t" + f"{round_coin_value(trade['profit_abs'], self._config['stake_currency'])} " + f"({trade['profit']:.2f}%) " + f"({trade['count']})\n") if len(output + stat_line) >= MAX_TELEGRAM_MESSAGE_LENGTH: self._send_msg(output, parse_mode=ParseMode.HTML) diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index 37b5045f8..6008ede66 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -929,7 +929,7 @@ def test_performance_handle(default_conf, update, ticker, fee, telegram._performance(update=update, context=MagicMock()) assert msg_mock.call_count == 1 assert 'Performance' in msg_mock.call_args_list[0][0][0] - assert 'ETH/BTC\t6.20% (1)' in msg_mock.call_args_list[0][0][0] + assert 'ETH/BTC\t0.00006217 BTC (6.20%) (1)' in msg_mock.call_args_list[0][0][0] def test_count_handle(default_conf, update, ticker, fee, mocker) -> None: