From f71eda1c2f90b26ccbbbb5b6cd1cae71a5055ff6 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 30 Apr 2019 06:23:14 +0200 Subject: [PATCH 1/3] Have forcesell return a result --- freqtrade/rpc/rpc.py | 5 +++-- freqtrade/rpc/telegram.py | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index aac419fe1..007b7686d 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -346,7 +346,7 @@ class RPC(object): return {'status': 'No more buy will occur from now. Run /reload_conf to reset.'} - def _rpc_forcesell(self, trade_id) -> None: + def _rpc_forcesell(self, trade_id) -> Dict[str, str]: """ Handler for forcesell . Sells the given trade at current price @@ -386,7 +386,7 @@ class RPC(object): for trade in Trade.get_open_trades(): _exec_forcesell(trade) Trade.session.flush() - return + return {'result': 'Created sell orders for all open trades.'} # Query for trade trade = Trade.query.filter( @@ -401,6 +401,7 @@ class RPC(object): _exec_forcesell(trade) Trade.session.flush() + return {'result': f'Created sell orders for trade {trade_id}.'} def _rpc_forcebuy(self, pair: str, price: Optional[float]) -> Optional[Trade]: """ diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index c61193d29..dc0bad2b2 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -413,7 +413,9 @@ class Telegram(RPC): trade_id = update.message.text.replace('/forcesell', '').strip() try: - self._rpc_forcesell(trade_id) + msg = self._rpc_forcesell(trade_id) + self._send_msg('Forcesell Result: `{result}`'.format(**msg), bot=bot) + except RPCException as e: self._send_msg(str(e), bot=bot) From 91642b2bd9608b5edee8fe9253278163ac1a885f Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 30 Apr 2019 06:25:02 +0200 Subject: [PATCH 2/3] Add tsts for forcesell-answers --- freqtrade/tests/rpc/test_rpc.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/freqtrade/tests/rpc/test_rpc.py b/freqtrade/tests/rpc/test_rpc.py index 25d1109b2..e1feffec8 100644 --- a/freqtrade/tests/rpc/test_rpc.py +++ b/freqtrade/tests/rpc/test_rpc.py @@ -463,12 +463,15 @@ def test_rpc_forcesell(default_conf, ticker, fee, mocker, markets) -> None: with pytest.raises(RPCException, match=r'.*invalid argument*'): rpc._rpc_forcesell(None) - rpc._rpc_forcesell('all') + msg = rpc._rpc_forcesell('all') + assert msg == {'result': 'Created sell orders for all open trades.'} freqtradebot.create_trade() - rpc._rpc_forcesell('all') + msg = rpc._rpc_forcesell('all') + assert msg == {'result': 'Created sell orders for all open trades.'} - rpc._rpc_forcesell('1') + msg = rpc._rpc_forcesell('1') + assert msg == {'result': 'Created sell orders for trade 1.'} freqtradebot.state = State.STOPPED with pytest.raises(RPCException, match=r'.*trader is not running*'): @@ -511,7 +514,8 @@ def test_rpc_forcesell(default_conf, ticker, fee, mocker, markets) -> None: } ) # check that the trade is called, which is done by ensuring exchange.cancel_order is called - rpc._rpc_forcesell('2') + msg = rpc._rpc_forcesell('2') + assert msg == {'result': 'Created sell orders for trade 2.'} assert cancel_order_mock.call_count == 2 assert trade.amount == amount @@ -525,7 +529,8 @@ def test_rpc_forcesell(default_conf, ticker, fee, mocker, markets) -> None: 'side': 'sell' } ) - rpc._rpc_forcesell('3') + msg = rpc._rpc_forcesell('3') + assert msg == {'result': 'Created sell orders for trade 3.'} # status quo, no exchange calls assert cancel_order_mock.call_count == 2 From 46214ce7cd690609bbd1c1c171e9b6a3e7a08306 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 1 May 2019 16:21:14 +0200 Subject: [PATCH 3/3] Fix typo after feedback --- freqtrade/rpc/rpc.py | 2 +- freqtrade/tests/rpc/test_rpc.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index 007b7686d..af384da45 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -401,7 +401,7 @@ class RPC(object): _exec_forcesell(trade) Trade.session.flush() - return {'result': f'Created sell orders for trade {trade_id}.'} + return {'result': f'Created sell order for trade {trade_id}.'} def _rpc_forcebuy(self, pair: str, price: Optional[float]) -> Optional[Trade]: """ diff --git a/freqtrade/tests/rpc/test_rpc.py b/freqtrade/tests/rpc/test_rpc.py index e1feffec8..93de6ef89 100644 --- a/freqtrade/tests/rpc/test_rpc.py +++ b/freqtrade/tests/rpc/test_rpc.py @@ -471,7 +471,7 @@ def test_rpc_forcesell(default_conf, ticker, fee, mocker, markets) -> None: assert msg == {'result': 'Created sell orders for all open trades.'} msg = rpc._rpc_forcesell('1') - assert msg == {'result': 'Created sell orders for trade 1.'} + assert msg == {'result': 'Created sell order for trade 1.'} freqtradebot.state = State.STOPPED with pytest.raises(RPCException, match=r'.*trader is not running*'): @@ -515,7 +515,7 @@ def test_rpc_forcesell(default_conf, ticker, fee, mocker, markets) -> None: ) # check that the trade is called, which is done by ensuring exchange.cancel_order is called msg = rpc._rpc_forcesell('2') - assert msg == {'result': 'Created sell orders for trade 2.'} + assert msg == {'result': 'Created sell order for trade 2.'} assert cancel_order_mock.call_count == 2 assert trade.amount == amount @@ -530,7 +530,7 @@ def test_rpc_forcesell(default_conf, ticker, fee, mocker, markets) -> None: } ) msg = rpc._rpc_forcesell('3') - assert msg == {'result': 'Created sell orders for trade 3.'} + assert msg == {'result': 'Created sell order for trade 3.'} # status quo, no exchange calls assert cancel_order_mock.call_count == 2