extract nested force_exit function to private instance function

This commit is contained in:
Matthias 2022-08-02 19:54:37 +02:00
parent 82aecc81f3
commit daf015d007

View File

@ -660,14 +660,7 @@ class RPC:
return {'status': 'No more buy will occur from now. Run /reload_config to reset.'} return {'status': 'No more buy will occur from now. Run /reload_config to reset.'}
def _rpc_force_exit(self, trade_id: str, ordertype: Optional[str] = None, *, def __exec_force_exit(self, trade: Trade, ordertype: Optional[str],
amount: Optional[float]) -> Dict[str, str]:
"""
Handler for forceexit <id>.
Sells the given trade at current price
"""
def _exec_force_exit(trade: Trade, ordertype: Optional[str],
_amount: Optional[float] = None) -> None: _amount: Optional[float] = None) -> None:
# Check if there is there is an open order # Check if there is there is an open order
fully_canceled = False fully_canceled = False
@ -703,6 +696,13 @@ class RPC:
trade, current_rate, exit_check, ordertype=order_type, trade, current_rate, exit_check, ordertype=order_type,
sub_trade_amt=sub_amount) sub_trade_amt=sub_amount)
def _rpc_force_exit(self, trade_id: str, ordertype: Optional[str] = None, *,
amount: Optional[float]) -> Dict[str, str]:
"""
Handler for forceexit <id>.
Sells the given trade at current price
"""
if self._freqtrade.state != State.RUNNING: if self._freqtrade.state != State.RUNNING:
raise RPCException('trader is not running') raise RPCException('trader is not running')
@ -710,7 +710,7 @@ class RPC:
if trade_id == 'all': if trade_id == 'all':
# Execute sell for all open orders # Execute sell for all open orders
for trade in Trade.get_open_trades(): for trade in Trade.get_open_trades():
_exec_force_exit(trade) self.__exec_force_exit(trade)
Trade.commit() Trade.commit()
self._freqtrade.wallets.update() self._freqtrade.wallets.update()
return {'result': 'Created sell orders for all open trades.'} return {'result': 'Created sell orders for all open trades.'}
@ -723,7 +723,7 @@ class RPC:
logger.warning('force_exit: Invalid argument received') logger.warning('force_exit: Invalid argument received')
raise RPCException('invalid argument') raise RPCException('invalid argument')
_exec_force_exit(trade, ordertype, amount) self.__exec_force_exit(trade, ordertype, amount)
Trade.commit() Trade.commit()
self._freqtrade.wallets.update() self._freqtrade.wallets.update()
return {'result': f'Created sell order for trade {trade_id}.'} return {'result': f'Created sell order for trade {trade_id}.'}