move endpoint definitions to class scope
This commit is contained in:
parent
75de61843b
commit
446c621006
@ -25,23 +25,48 @@ class ApiServerSuperWrap(RPC):
|
|||||||
"""
|
"""
|
||||||
super().__init__(freqtrade)
|
super().__init__(freqtrade)
|
||||||
|
|
||||||
self.interval = 1
|
|
||||||
|
|
||||||
thread = threading.Thread(target=self.run, args=(freqtrade,)) # extra comma as ref ! Tuple
|
|
||||||
thread.daemon = True # Daemonize thread
|
|
||||||
thread.start() # Start the execution
|
|
||||||
|
|
||||||
|
|
||||||
def run(self, freqtrade):
|
|
||||||
""" Method that runs forever """
|
|
||||||
self._config = freqtrade.config
|
self._config = freqtrade.config
|
||||||
|
|
||||||
|
thread = threading.Thread(target=self.run, daemon=True)
|
||||||
|
thread.start()
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
""" Method that runs forever """
|
||||||
|
|
||||||
|
# defines the url rules available on the api server
|
||||||
|
'''
|
||||||
|
First two arguments passed are /URL and 'Label'
|
||||||
|
Label can be used as a shortcut when refactoring
|
||||||
|
'''
|
||||||
|
app.add_url_rule('/', 'hello', view_func=self.hello, methods=['GET'])
|
||||||
|
app.add_url_rule('/stop', 'stop', view_func=self.stop, methods=['GET'])
|
||||||
|
app.add_url_rule('/start', 'start', view_func=self.start, methods=['GET'])
|
||||||
|
app.add_url_rule('/daily', 'daily', view_func=self.daily, methods=['GET'])
|
||||||
|
|
||||||
|
"""
|
||||||
|
Section to handle configuration and running of the Rest server
|
||||||
|
also to check and warn if not bound to a loopback, warn on security risk.
|
||||||
|
"""
|
||||||
|
rest_ip = self._config['api_server']['listen_ip_address']
|
||||||
|
rest_port = self._config['api_server']['listen_port']
|
||||||
|
|
||||||
|
logger.info('Starting HTTP Server at {}:{}'.format(rest_ip, rest_port))
|
||||||
|
if not IPv4Address(rest_ip).is_loopback:
|
||||||
|
logger.info("SECURITY WARNING - Local Rest Server listening to external connections")
|
||||||
|
logger.info("SECURITY WARNING - This is insecure please set to your loopback, e.g 127.0.0.1 in config.json")
|
||||||
|
|
||||||
|
# Run the Server
|
||||||
|
logger.info('Starting Local Rest Server')
|
||||||
|
try:
|
||||||
|
app.run(host=rest_ip, port=rest_port)
|
||||||
|
except Exception:
|
||||||
|
logger.exception("Api server failed to start, exception message is:")
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Define the application methods here, called by app.add_url_rule
|
Define the application methods here, called by app.add_url_rule
|
||||||
each Telegram command should have a like local substitute
|
each Telegram command should have a like local substitute
|
||||||
"""
|
"""
|
||||||
# @app.route("/")
|
def hello(self):
|
||||||
def hello():
|
|
||||||
# For simple rest server testing via browser
|
# For simple rest server testing via browser
|
||||||
# cmds = 'Try uri:/daily?timescale=7 /profit /balance /status
|
# cmds = 'Try uri:/daily?timescale=7 /profit /balance /status
|
||||||
# /status /table /performance /count,
|
# /status /table /performance /count,
|
||||||
@ -55,7 +80,7 @@ class ApiServerSuperWrap(RPC):
|
|||||||
'<a href=/start>/start</a>'
|
'<a href=/start>/start</a>'
|
||||||
return rest_cmds
|
return rest_cmds
|
||||||
|
|
||||||
def daily():
|
def daily(self):
|
||||||
try:
|
try:
|
||||||
timescale = request.args.get('timescale')
|
timescale = request.args.get('timescale')
|
||||||
logger.info("LocalRPC - Daily Command Called")
|
logger.info("LocalRPC - Daily Command Called")
|
||||||
@ -71,7 +96,7 @@ class ApiServerSuperWrap(RPC):
|
|||||||
except RPCException as e:
|
except RPCException as e:
|
||||||
return e
|
return e
|
||||||
|
|
||||||
def start():
|
def start(self):
|
||||||
"""
|
"""
|
||||||
Handler for /start.
|
Handler for /start.
|
||||||
Starts TradeThread
|
Starts TradeThread
|
||||||
@ -79,41 +104,10 @@ class ApiServerSuperWrap(RPC):
|
|||||||
msg = self._rpc_start()
|
msg = self._rpc_start()
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
def stop():
|
def stop(self):
|
||||||
"""
|
"""
|
||||||
Handler for /stop.
|
Handler for /stop.
|
||||||
Stops TradeThread
|
Stops TradeThread
|
||||||
"""
|
"""
|
||||||
msg = self._rpc_stop()
|
msg = self._rpc_stop()
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
## defines the url rules available on the api server
|
|
||||||
'''
|
|
||||||
First two arguments passed are /URL and 'Label'
|
|
||||||
Label can be used as a shortcut when refactoring
|
|
||||||
'''
|
|
||||||
app.add_url_rule('/', 'hello', view_func=hello, methods=['GET'])
|
|
||||||
app.add_url_rule('/stop', 'stop', view_func=stop, methods=['GET'])
|
|
||||||
app.add_url_rule('/start', 'start', view_func=start, methods=['GET'])
|
|
||||||
app.add_url_rule('/daily', 'daily', view_func=daily, methods=['GET'])
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
Section to handle configuration and running of the Rest server
|
|
||||||
also to check and warn if not bound to a loopback, warn on security risk.
|
|
||||||
"""
|
|
||||||
rest_ip = self._config['api_server']['listen_ip_address']
|
|
||||||
rest_port = self._config['api_server']['listen_port']
|
|
||||||
|
|
||||||
if not IPv4Address(rest_ip).is_loopback :
|
|
||||||
logger.info("SECURITY WARNING - Local Rest Server listening to external connections")
|
|
||||||
logger.info("SECURITY WARNING - This is insecure please set to your loopback, e.g 127.0.0.1 in config.json")
|
|
||||||
|
|
||||||
# Run the Server
|
|
||||||
logger.info('Starting Local Rest Server')
|
|
||||||
try:
|
|
||||||
app.run(host=rest_ip, port=rest_port)
|
|
||||||
except:
|
|
||||||
logger.exception("Api server failed to start, exception message is:")
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user