Implement a few more methods

This commit is contained in:
Matthias 2019-04-06 19:58:00 +02:00
parent 8993882dcb
commit 3cf6c6ee0c

View File

@ -37,6 +37,8 @@ class ApiServer(RPC):
def cleanup(self) -> None: def cleanup(self) -> None:
logger.info("Stopping API Server") logger.info("Stopping API Server")
# TODO: Gracefully shutdown - right now it'll fail on /reload_conf
# since it's not terminated correctly.
def send_msg(self, msg: Dict[str, str]) -> None: def send_msg(self, msg: Dict[str, str]) -> None:
"""We don't push to endpoints at the moment. Look at webhooks for that.""" """We don't push to endpoints at the moment. Look at webhooks for that."""
@ -62,8 +64,13 @@ class ApiServer(RPC):
Label can be used as a shortcut when refactoring Label can be used as a shortcut when refactoring
:return: :return:
""" """
app.add_url_rule('/stop', 'stop', view_func=self.stop, methods=['GET']) # TODO: actions should not be GET...
app.add_url_rule('/start', 'start', view_func=self.start, methods=['GET']) app.add_url_rule('/start', 'start', view_func=self.start, methods=['GET'])
app.add_url_rule('/stop', 'stop', view_func=self.stop, methods=['GET'])
app.add_url_rule('/stopbuy', 'stopbuy', view_func=self.stopbuy, methods=['GET'])
app.add_url_rule('/reload_conf', 'reload_conf', view_func=self.reload_conf,
methods=['GET'])
app.add_url_rule('/count', 'count', view_func=self.count, methods=['GET'])
app.add_url_rule('/daily', 'daily', view_func=self.daily, methods=['GET']) app.add_url_rule('/daily', 'daily', view_func=self.daily, methods=['GET'])
app.add_url_rule('/profit', 'profit', view_func=self.profit, methods=['GET']) app.add_url_rule('/profit', 'profit', view_func=self.profit, methods=['GET'])
app.add_url_rule('/status_table', 'status_table', app.add_url_rule('/status_table', 'status_table',
@ -198,3 +205,31 @@ class ApiServer(RPC):
""" """
msg = self._rpc_stop() msg = self._rpc_stop()
return self.rest_dump(msg) return self.rest_dump(msg)
def stopbuy(self):
"""
Handler for /stopbuy.
Sets max_open_trades to 0 and gracefully sells all open trades
"""
msg = self._rpc_stopbuy()
return self.rest_dump(msg)
def reload_conf(self):
"""
Handler for /reload_conf.
Triggers a config file reload
"""
msg = self._rpc_reload_conf()
return self.rest_dump(msg)
def count(self):
"""
Handler for /count.
Returns the number of trades running
"""
try:
msg = self._rpc_count()
except RPCException as e:
msg = {"status": str(e)}
return self.rest_dump(msg)