Add telegram /delete command to delete tradeid
code inspired from _rpc_forcesell
This commit is contained in:
parent
dd3a2675b5
commit
08fdd7d863
@ -537,6 +537,28 @@ class RPC:
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def _rpc_delete(self, trade_id: str) -> Dict[str, str]:
|
||||||
|
"""
|
||||||
|
Handler for delete <id>.
|
||||||
|
Delete the given trade
|
||||||
|
"""
|
||||||
|
def _exec_delete(trade: Trade) -> None:
|
||||||
|
Trade.session.delete(trade)
|
||||||
|
Trade.session.flush()
|
||||||
|
|
||||||
|
with self._freqtrade._sell_lock:
|
||||||
|
trade = Trade.get_trades(
|
||||||
|
trade_filter=[Trade.id == trade_id, ]
|
||||||
|
).first()
|
||||||
|
if not trade:
|
||||||
|
logger.warning('delete: Invalid argument received')
|
||||||
|
raise RPCException('invalid argument')
|
||||||
|
|
||||||
|
_exec_delete(trade)
|
||||||
|
Trade.session.flush()
|
||||||
|
self._freqtrade.wallets.update()
|
||||||
|
return {'result': f'Deleted trade {trade_id}.'}
|
||||||
|
|
||||||
def _rpc_performance(self) -> List[Dict[str, Any]]:
|
def _rpc_performance(self) -> List[Dict[str, Any]]:
|
||||||
"""
|
"""
|
||||||
Handler for performance.
|
Handler for performance.
|
||||||
|
@ -93,6 +93,7 @@ class Telegram(RPC):
|
|||||||
CommandHandler('forcesell', self._forcesell),
|
CommandHandler('forcesell', self._forcesell),
|
||||||
CommandHandler('forcebuy', self._forcebuy),
|
CommandHandler('forcebuy', self._forcebuy),
|
||||||
CommandHandler('trades', self._trades),
|
CommandHandler('trades', self._trades),
|
||||||
|
CommandHandler('delete', self._delete),
|
||||||
CommandHandler('performance', self._performance),
|
CommandHandler('performance', self._performance),
|
||||||
CommandHandler('daily', self._daily),
|
CommandHandler('daily', self._daily),
|
||||||
CommandHandler('count', self._count),
|
CommandHandler('count', self._count),
|
||||||
@ -497,6 +498,24 @@ class Telegram(RPC):
|
|||||||
except RPCException as e:
|
except RPCException as e:
|
||||||
self._send_msg(str(e))
|
self._send_msg(str(e))
|
||||||
|
|
||||||
|
@authorized_only
|
||||||
|
def _delete(self, update: Update, context: CallbackContext) -> None:
|
||||||
|
"""
|
||||||
|
Handler for /delete <id>.
|
||||||
|
Delete the given trade
|
||||||
|
:param bot: telegram bot
|
||||||
|
:param update: message update
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
|
||||||
|
trade_id = context.args[0] if len(context.args) > 0 else None
|
||||||
|
try:
|
||||||
|
msg = self._rpc_delete(trade_id)
|
||||||
|
self._send_msg('Delete Result: `{result}`'.format(**msg))
|
||||||
|
|
||||||
|
except RPCException as e:
|
||||||
|
self._send_msg(str(e))
|
||||||
|
|
||||||
@authorized_only
|
@authorized_only
|
||||||
def _trades(self, update: Update, context: CallbackContext) -> None:
|
def _trades(self, update: Update, context: CallbackContext) -> None:
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user