Run webserver in main thread when using webserver mode

This commit is contained in:
Matthias 2021-03-21 10:45:44 +01:00
parent 37b15e830a
commit 03140a0ecb
2 changed files with 6 additions and 3 deletions

View File

@ -339,14 +339,14 @@ def api_get_backtest():
Get backtesting result. Get backtesting result.
Returns Result after backtesting has been ran. Returns Result after backtesting has been ran.
""" """
from freqtrade.persistence import Trade from freqtrade.persistence import LocalTrade
if ApiServer._bgtask_running: if ApiServer._bgtask_running:
return { return {
"status": "running", "status": "running",
"running": True, "running": True,
"step": ApiServer._bt.get_action() if ApiServer._bt else str(BacktestState.STARTUP), "step": ApiServer._bt.get_action() if ApiServer._bt else str(BacktestState.STARTUP),
"progress": ApiServer._bt.get_progress() if ApiServer._bt else 0, "progress": ApiServer._bt.get_progress() if ApiServer._bt else 0,
"trade_count": Trade.get_trades_proxy(is_open=False), "trade_count": len(LocalTrade.trades),
"status_msg": "Backtest running", "status_msg": "Backtest running",
} }

View File

@ -166,6 +166,9 @@ class ApiServer(RPCHandler):
) )
try: try:
self._server = UvicornServer(uvconfig) self._server = UvicornServer(uvconfig)
if self._standalone:
self._server.run()
else:
self._server.run_in_thread() self._server.run_in_thread()
except Exception: except Exception:
logger.exception("Api server failed to start.") logger.exception("Api server failed to start.")