Merge pull request #1814 from freqtrade/rpc/forcesell

immediately confirm forcesell
This commit is contained in:
Misagh 2019-05-01 16:47:22 +02:00 committed by GitHub
commit de6112adb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 8 deletions

View File

@ -346,7 +346,7 @@ class RPC(object):
return {'status': 'No more buy will occur from now. Run /reload_conf to reset.'} 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 <id>. Handler for forcesell <id>.
Sells the given trade at current price Sells the given trade at current price
@ -386,7 +386,7 @@ class RPC(object):
for trade in Trade.get_open_trades(): for trade in Trade.get_open_trades():
_exec_forcesell(trade) _exec_forcesell(trade)
Trade.session.flush() Trade.session.flush()
return return {'result': 'Created sell orders for all open trades.'}
# Query for trade # Query for trade
trade = Trade.query.filter( trade = Trade.query.filter(
@ -401,6 +401,7 @@ class RPC(object):
_exec_forcesell(trade) _exec_forcesell(trade)
Trade.session.flush() Trade.session.flush()
return {'result': f'Created sell order for trade {trade_id}.'}
def _rpc_forcebuy(self, pair: str, price: Optional[float]) -> Optional[Trade]: def _rpc_forcebuy(self, pair: str, price: Optional[float]) -> Optional[Trade]:
""" """

View File

@ -413,7 +413,9 @@ class Telegram(RPC):
trade_id = update.message.text.replace('/forcesell', '').strip() trade_id = update.message.text.replace('/forcesell', '').strip()
try: 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: except RPCException as e:
self._send_msg(str(e), bot=bot) self._send_msg(str(e), bot=bot)

View File

@ -463,12 +463,15 @@ def test_rpc_forcesell(default_conf, ticker, fee, mocker, markets) -> None:
with pytest.raises(RPCException, match=r'.*invalid argument*'): with pytest.raises(RPCException, match=r'.*invalid argument*'):
rpc._rpc_forcesell(None) 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() 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 order for trade 1.'}
freqtradebot.state = State.STOPPED freqtradebot.state = State.STOPPED
with pytest.raises(RPCException, match=r'.*trader is not running*'): 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 # 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 order for trade 2.'}
assert cancel_order_mock.call_count == 2 assert cancel_order_mock.call_count == 2
assert trade.amount == amount assert trade.amount == amount
@ -525,7 +529,8 @@ def test_rpc_forcesell(default_conf, ticker, fee, mocker, markets) -> None:
'side': 'sell' 'side': 'sell'
} }
) )
rpc._rpc_forcesell('3') msg = rpc._rpc_forcesell('3')
assert msg == {'result': 'Created sell order for trade 3.'}
# status quo, no exchange calls # status quo, no exchange calls
assert cancel_order_mock.call_count == 2 assert cancel_order_mock.call_count == 2