Implement /delete for api-server

This commit is contained in:
Matthias 2020-08-04 14:41:22 +02:00
parent c0083c4244
commit 215972c68f
3 changed files with 14 additions and 3 deletions

View File

@ -200,6 +200,8 @@ class ApiServer(RPC):
view_func=self._ping, methods=['GET'])
self.app.add_url_rule(f'{BASE_URI}/trades', 'trades',
view_func=self._trades, methods=['GET'])
self.app.add_url_rule(f'{BASE_URI}/trades/<int:tradeid>', 'trades_delete',
view_func=self._trades_delete, methods=['DELETE'])
# Combined actions and infos
self.app.add_url_rule(f'{BASE_URI}/blacklist', 'blacklist', view_func=self._blacklist,
methods=['GET', 'POST'])
@ -424,6 +426,15 @@ class ApiServer(RPC):
results = self._rpc_trade_history(limit)
return self.rest_dump(results)
@require_login
@rpc_catch_errors
def _trades_delete(self, tradeid):
"""
Handler for DELETE /trades/<tradeid> endpoint.
"""
result = self._rpc_delete(tradeid)
return self.rest_dump(result)
@require_login
@rpc_catch_errors
def _whitelist(self):

View File

@ -537,7 +537,7 @@ class RPC:
return trade
else:
return None
def _rpc_delete(self, trade_id: str) -> Dict[str, str]:
"""
Handler for delete <id>.
@ -558,7 +558,7 @@ class RPC:
_exec_delete(trade)
Trade.session.flush()
self._freqtrade.wallets.update()
return {'result': f'Deleted trade {trade_id}.'}
return {'result_msg': f'Deleted trade {trade_id}.'}
def _rpc_performance(self) -> List[Dict[str, Any]]:
"""

View File

@ -547,7 +547,7 @@ class Telegram(RPC):
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))
self._send_msg('Delete Result: `{result_msg}`'.format(**msg))
except RPCException as e:
self._send_msg(str(e))