change var names
This commit is contained in:
parent
e256ebd727
commit
426f8f37e9
@ -502,7 +502,7 @@ CONF_SCHEMA = {
|
|||||||
'required': ['name', 'url', 'ws_token']
|
'required': ['name', 'url', 'ws_token']
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'reply_timeout': {'type': 'integer'},
|
'wait_timeout': {'type': 'integer'},
|
||||||
'sleep_time': {'type': 'integer'},
|
'sleep_time': {'type': 'integer'},
|
||||||
'ping_timeout': {'type': 'integer'},
|
'ping_timeout': {'type': 'integer'},
|
||||||
'remove_signals_analyzed_df': {'type': 'boolean', 'default': False},
|
'remove_signals_analyzed_df': {'type': 'boolean', 'default': False},
|
||||||
|
@ -49,9 +49,9 @@ class ApiServer(RPCHandler):
|
|||||||
# Exchange - only available in webserver mode.
|
# Exchange - only available in webserver mode.
|
||||||
_exchange = None
|
_exchange = None
|
||||||
# websocket message queue stuff
|
# websocket message queue stuff
|
||||||
_channel_manager = None
|
_ws_channel_manager = None
|
||||||
_thread = None
|
_ws_thread = None
|
||||||
_loop = None
|
_ws_loop = None
|
||||||
|
|
||||||
def __new__(cls, *args, **kwargs):
|
def __new__(cls, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
@ -69,14 +69,14 @@ class ApiServer(RPCHandler):
|
|||||||
return
|
return
|
||||||
self._standalone: bool = standalone
|
self._standalone: bool = standalone
|
||||||
self._server = None
|
self._server = None
|
||||||
self._queue = None
|
self._ws_queue = None
|
||||||
self._background_task = None
|
self._ws_background_task = None
|
||||||
|
|
||||||
ApiServer.__initialized = True
|
ApiServer.__initialized = True
|
||||||
|
|
||||||
api_config = self._config['api_server']
|
api_config = self._config['api_server']
|
||||||
|
|
||||||
ApiServer._channel_manager = ChannelManager()
|
ApiServer._ws_channel_manager = ChannelManager()
|
||||||
|
|
||||||
self.app = FastAPI(title="Freqtrade API",
|
self.app = FastAPI(title="Freqtrade API",
|
||||||
docs_url='/docs' if api_config.get('enable_openapi', False) else None,
|
docs_url='/docs' if api_config.get('enable_openapi', False) else None,
|
||||||
@ -105,18 +105,18 @@ class ApiServer(RPCHandler):
|
|||||||
logger.info("Stopping API Server")
|
logger.info("Stopping API Server")
|
||||||
self._server.cleanup()
|
self._server.cleanup()
|
||||||
|
|
||||||
if self._thread and self._loop:
|
if self._ws_thread and self._ws_loop:
|
||||||
logger.info("Stopping API Server background tasks")
|
logger.info("Stopping API Server background tasks")
|
||||||
|
|
||||||
if self._background_task:
|
if self._ws_background_task:
|
||||||
# Cancel the queue task
|
# Cancel the queue task
|
||||||
self._background_task.cancel()
|
self._ws_background_task.cancel()
|
||||||
|
|
||||||
self._thread.join()
|
self._ws_thread.join()
|
||||||
|
|
||||||
self._thread = None
|
self._ws_thread = None
|
||||||
self._loop = None
|
self._ws_loop = None
|
||||||
self._background_task = None
|
self._ws_background_task = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def shutdown(cls):
|
def shutdown(cls):
|
||||||
@ -127,8 +127,8 @@ class ApiServer(RPCHandler):
|
|||||||
cls._rpc = None
|
cls._rpc = None
|
||||||
|
|
||||||
def send_msg(self, msg: Dict[str, str]) -> None:
|
def send_msg(self, msg: Dict[str, str]) -> None:
|
||||||
if self._queue:
|
if self._ws_queue:
|
||||||
sync_q = self._queue.sync_q
|
sync_q = self._ws_queue.sync_q
|
||||||
sync_q.put(msg)
|
sync_q.put(msg)
|
||||||
|
|
||||||
def handle_rpc_exception(self, request, exc):
|
def handle_rpc_exception(self, request, exc):
|
||||||
@ -170,24 +170,24 @@ class ApiServer(RPCHandler):
|
|||||||
app.add_exception_handler(RPCException, self.handle_rpc_exception)
|
app.add_exception_handler(RPCException, self.handle_rpc_exception)
|
||||||
|
|
||||||
def start_message_queue(self):
|
def start_message_queue(self):
|
||||||
if self._thread:
|
if self._ws_thread:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Create a new loop, as it'll be just for the background thread
|
# Create a new loop, as it'll be just for the background thread
|
||||||
self._loop = asyncio.new_event_loop()
|
self._ws_loop = asyncio.new_event_loop()
|
||||||
|
|
||||||
# Start the thread
|
# Start the thread
|
||||||
self._thread = Thread(target=self._loop.run_forever)
|
self._ws_thread = Thread(target=self._ws_loop.run_forever)
|
||||||
self._thread.start()
|
self._ws_thread.start()
|
||||||
|
|
||||||
# Finally, submit the coro to the thread
|
# Finally, submit the coro to the thread
|
||||||
self._background_task = asyncio.run_coroutine_threadsafe(
|
self._ws_background_task = asyncio.run_coroutine_threadsafe(
|
||||||
self._broadcast_queue_data(), loop=self._loop)
|
self._broadcast_queue_data(), loop=self._ws_loop)
|
||||||
|
|
||||||
async def _broadcast_queue_data(self):
|
async def _broadcast_queue_data(self):
|
||||||
# Instantiate the queue in this coroutine so it's attached to our loop
|
# Instantiate the queue in this coroutine so it's attached to our loop
|
||||||
self._queue = ThreadedQueue()
|
self._ws_queue = ThreadedQueue()
|
||||||
async_queue = self._queue.async_q
|
async_queue = self._ws_queue.async_q
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
@ -196,13 +196,13 @@ class ApiServer(RPCHandler):
|
|||||||
message = await async_queue.get()
|
message = await async_queue.get()
|
||||||
logger.debug(f"Found message of type: {message.get('type')}")
|
logger.debug(f"Found message of type: {message.get('type')}")
|
||||||
# Broadcast it
|
# Broadcast it
|
||||||
await self._channel_manager.broadcast(message)
|
await self._ws_channel_manager.broadcast(message)
|
||||||
# Sleep, make this configurable?
|
# Sleep, make this configurable?
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
# Disconnect channels and stop the loop on cancel
|
# Disconnect channels and stop the loop on cancel
|
||||||
await self._channel_manager.disconnect_all()
|
await self._ws_channel_manager.disconnect_all()
|
||||||
self._loop.stop()
|
self._ws_loop.stop()
|
||||||
|
|
||||||
# For testing, shouldn't happen when stable
|
# For testing, shouldn't happen when stable
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -59,9 +59,9 @@ class ExternalMessageConsumer:
|
|||||||
if self.enabled and len(self.producers) < 1:
|
if self.enabled and len(self.producers) < 1:
|
||||||
raise ValueError("You must specify at least 1 Producer to connect to.")
|
raise ValueError("You must specify at least 1 Producer to connect to.")
|
||||||
|
|
||||||
self.reply_timeout = self._emc_config.get('reply_timeout', 30)
|
self.wait_timeout = self._emc_config.get('wait_timeout', 300) # in seconds
|
||||||
self.ping_timeout = self._emc_config.get('ping_timeout', 5)
|
self.ping_timeout = self._emc_config.get('ping_timeout', 10) # in seconds
|
||||||
self.sleep_time = self._emc_config.get('sleep_time', 10)
|
self.sleep_time = self._emc_config.get('sleep_time', 10) # in seconds
|
||||||
|
|
||||||
# The amount of candles per dataframe on the initial request
|
# The amount of candles per dataframe on the initial request
|
||||||
self.initial_candle_limit = self._emc_config.get('initial_candle_limit', 1500)
|
self.initial_candle_limit = self._emc_config.get('initial_candle_limit', 1500)
|
||||||
@ -220,7 +220,7 @@ class ExternalMessageConsumer:
|
|||||||
try:
|
try:
|
||||||
message = await asyncio.wait_for(
|
message = await asyncio.wait_for(
|
||||||
channel.recv(),
|
channel.recv(),
|
||||||
timeout=self.reply_timeout
|
timeout=self.wait_timeout
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user