From 3925e8a7e3a91c6a500293557c9e8013efad4220 Mon Sep 17 00:00:00 2001 From: Stefano Ariestasia Date: Wed, 19 Jan 2022 16:14:21 +0900 Subject: [PATCH 1/2] add "# Buys" column to status table --- freqtrade/rpc/rpc.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index e568fca8c..41fd37e51 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -238,19 +238,26 @@ class RPC: profit_str += f" ({fiat_profit:.2f})" fiat_profit_sum = fiat_profit if isnan(fiat_profit_sum) \ else fiat_profit_sum + fiat_profit - trades_list.append([ + detail_trade = [ trade.id, trade.pair + ('*' if (trade.open_order_id is not None and trade.close_rate_requested is None) else '') + ('**' if (trade.close_rate_requested is not None) else ''), shorten_date(arrow.get(trade.open_date).humanize(only_distance=True)), profit_str - ]) + ] + if self._config.get('position_adjustment_enable', False): + filled_buys = trade.select_filled_orders('buy') + detail_trade.append(str(len(filled_buys))) + trades_list.append(detail_trade) profitcol = "Profit" if self._fiat_converter: profitcol += " (" + fiat_display_currency + ")" - columns = ['ID', 'Pair', 'Since', profitcol] + if self._config.get('position_adjustment_enable', False): + columns = ['ID', 'Pair', 'Since', profitcol, '# Buys'] + else: + columns = ['ID', 'Pair', 'Since', profitcol] return trades_list, columns, fiat_profit_sum def _rpc_daily_profit( From d02acb21c2ea6bb53786619193c8da226a0174e6 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 21 Jan 2022 07:04:25 +0100 Subject: [PATCH 2/2] Add simple test for #buy header --- freqtrade/rpc/rpc.py | 2 +- tests/rpc/test_rpc.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index 41fd37e51..e969aa0a7 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -242,7 +242,7 @@ class RPC: trade.id, trade.pair + ('*' if (trade.open_order_id is not None and trade.close_rate_requested is None) else '') - + ('**' if (trade.close_rate_requested is not None) else ''), + + ('**' if (trade.close_rate_requested is not None) else ''), shorten_date(arrow.get(trade.open_date).humanize(only_distance=True)), profit_str ] diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index e86022a91..fd43df019 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -214,11 +214,17 @@ def test_rpc_status_table(default_conf, ticker, fee, mocker) -> None: result, headers, fiat_profit_sum = rpc._rpc_status_table(default_conf['stake_currency'], 'USD') assert "Since" in headers assert "Pair" in headers + assert len(result[0]) == 4 assert 'instantly' == result[0][2] assert 'ETH/BTC' in result[0][1] assert '-0.41% (-0.06)' == result[0][3] assert '-0.06' == f'{fiat_profit_sum:.2f}' + rpc._config['position_adjustment_enable'] = True + result, headers, fiat_profit_sum = rpc._rpc_status_table(default_conf['stake_currency'], 'USD') + assert "# Buys" in headers + assert len(result[0]) == 5 + mocker.patch('freqtrade.exchange.Exchange.get_rate', MagicMock(side_effect=ExchangeError("Pair 'ETH/BTC' not available"))) result, headers, fiat_profit_sum = rpc._rpc_status_table(default_conf['stake_currency'], 'USD')