From 7a598f32dcc0f45f326148ed98c4ea83278dce42 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 6 Apr 2019 19:58:45 +0200 Subject: [PATCH 1/2] Move rpc-count calculation to _rpc class --- freqtrade/rpc/rpc.py | 7 ++++++- freqtrade/rpc/telegram.py | 10 ++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index 88ade0c27..d3a6dc0db 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -459,7 +459,12 @@ class RPC(object): if self._freqtrade.state != State.RUNNING: raise RPCException('trader is not running') - return Trade.get_open_trades() + trades = Trade.get_open_trades() + return { + 'current': len(trades), + 'max': self._config['max_open_trades'], + 'total stake': sum((trade.open_rate * trade.amount) for trade in trades) + } def _rpc_whitelist(self) -> Dict: """ Returns the currently active whitelist""" diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index e17f73502..ca108b17e 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -456,12 +456,10 @@ class Telegram(RPC): :return: None """ try: - trades = self._rpc_count() - message = tabulate({ - 'current': [len(trades)], - 'max': [self._config['max_open_trades']], - 'total stake': [sum((trade.open_rate * trade.amount) for trade in trades)] - }, headers=['current', 'max', 'total stake'], tablefmt='simple') + counts = self._rpc_count() + message = tabulate({k: [v] for k, v in counts.items()}, + headers=['current', 'max', 'total stake'], + tablefmt='simple') message = "
{}
".format(message) logger.debug(message) self._send_msg(message, parse_mode=ParseMode.HTML) From f13917813637ca9bc64e764cc92a9876c3850e00 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 6 Apr 2019 20:01:29 +0200 Subject: [PATCH 2/2] rpc_counts should be in .rpc --- freqtrade/rpc/rpc.py | 6 +++--- freqtrade/tests/rpc/test_rpc.py | 10 ++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index d3a6dc0db..aac419fe1 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -454,7 +454,7 @@ class RPC(object): for pair, rate, count in pair_rates ] - def _rpc_count(self) -> List[Trade]: + def _rpc_count(self) -> Dict[str, float]: """ Returns the number of trades running """ if self._freqtrade.state != State.RUNNING: raise RPCException('trader is not running') @@ -462,8 +462,8 @@ class RPC(object): trades = Trade.get_open_trades() return { 'current': len(trades), - 'max': self._config['max_open_trades'], - 'total stake': sum((trade.open_rate * trade.amount) for trade in trades) + 'max': float(self._freqtrade.config['max_open_trades']), + 'total_stake': sum((trade.open_rate * trade.amount) for trade in trades) } def _rpc_whitelist(self) -> Dict: diff --git a/freqtrade/tests/rpc/test_rpc.py b/freqtrade/tests/rpc/test_rpc.py index 8b10a1314..25d1109b2 100644 --- a/freqtrade/tests/rpc/test_rpc.py +++ b/freqtrade/tests/rpc/test_rpc.py @@ -581,15 +581,13 @@ def test_rpc_count(mocker, default_conf, ticker, fee, markets) -> None: patch_get_signal(freqtradebot, (True, False)) rpc = RPC(freqtradebot) - trades = rpc._rpc_count() - nb_trades = len(trades) - assert nb_trades == 0 + counts = rpc._rpc_count() + assert counts["current"] == 0 # Create some test data freqtradebot.create_trade() - trades = rpc._rpc_count() - nb_trades = len(trades) - assert nb_trades == 1 + counts = rpc._rpc_count() + assert counts["current"] == 1 def test_rpcforcebuy(mocker, default_conf, ticker, fee, markets, limit_buy_order) -> None: