minor improvements, fixes, old config+constant removal
This commit is contained in:
@@ -50,6 +50,7 @@ def get_user_from_token(token, secret_key: str, token_type: str = "access"):
|
||||
|
||||
# This should be reimplemented to better realign with the existing tools provided
|
||||
# by FastAPI regarding API Tokens
|
||||
# https://github.com/tiangolo/fastapi/blob/master/fastapi/security/api_key.py
|
||||
async def get_ws_token(
|
||||
ws: WebSocket,
|
||||
token: Union[str, None] = None,
|
||||
|
@@ -2,23 +2,30 @@ import logging
|
||||
from typing import Any, Dict
|
||||
|
||||
from fastapi import APIRouter, Depends, WebSocket, WebSocketDisconnect
|
||||
# fastapi does not make this available through it, so import directly from starlette
|
||||
from starlette.websockets import WebSocketState
|
||||
|
||||
from freqtrade.enums import RPCMessageType, RPCRequestType
|
||||
from freqtrade.rpc.api_server.deps import get_channel_manager, get_rpc
|
||||
from freqtrade.rpc.api_server.ws.channel import WebSocketChannel
|
||||
from freqtrade.rpc.api_server.ws.utils import is_websocket_alive
|
||||
from freqtrade.rpc.rpc import RPC
|
||||
|
||||
|
||||
# from typing import Any, Dict
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Private router, protected by API Key authentication
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
async def is_websocket_alive(ws: WebSocket) -> bool:
|
||||
if (
|
||||
ws.application_state == WebSocketState.CONNECTED and
|
||||
ws.client_state == WebSocketState.CONNECTED
|
||||
):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
async def _process_consumer_request(
|
||||
request: Dict[str, Any],
|
||||
channel: WebSocketChannel,
|
||||
|
@@ -205,7 +205,7 @@ class ApiServer(RPCHandler):
|
||||
|
||||
# For testing, shouldn't happen when stable
|
||||
except Exception as e:
|
||||
logger.info(f"Exception happened in background task: {e}")
|
||||
logger.exception(f"Exception happened in background task: {e}")
|
||||
|
||||
def start_api(self):
|
||||
"""
|
||||
@@ -244,8 +244,7 @@ class ApiServer(RPCHandler):
|
||||
if self._standalone:
|
||||
self._server.run()
|
||||
else:
|
||||
if self._config.get('api_server', {}).get('enable_message_ws', False):
|
||||
self.start_message_queue()
|
||||
self.start_message_queue()
|
||||
self._server.run_in_thread()
|
||||
except Exception:
|
||||
logger.exception("Api server failed to start.")
|
||||
|
Reference in New Issue
Block a user