From 8821d781a9ada629b28a8db36d7ef5403276d608 Mon Sep 17 00:00:00 2001 From: mraniki <8766259+mraniki@users.noreply.github.com> Date: Fri, 5 Jul 2024 12:34:42 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- findmyorder/handler/handler.py | 10 ++++++---- findmyorder/main.py | 30 ++++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/findmyorder/handler/handler.py b/findmyorder/handler/handler.py index 7d4c1672..8726ae5a 100644 --- a/findmyorder/handler/handler.py +++ b/findmyorder/handler/handler.py @@ -25,7 +25,8 @@ def __init__(self, **kwargs): self.name = kwargs.get("name", None) self.client = None self.enabled = kwargs.get("enabled", None) - self.action_identifier = kwargs.get("action_identifier", None) + self.action_identifiers = kwargs.get("action_identifier", None) + self.action_identifiers = self.action_identifiers.lower() self.stop_loss_identifier = kwargs.get("stop_loss_identifier", None) self.take_profit_identifier = kwargs.get("take_profit_identifier", None) self.quantity_identifier = kwargs.get("quantity_identifier", None) @@ -63,9 +64,10 @@ async def search(self, message: str) -> bool: """ if message: order_identifier = message.split()[0].lower() - if order_identifier in ( - action.lower() for action in self.action_identifiers - ): + # logger.debug("Order identifier: {}", order_identifier) + # logger.debug("Action identifiers: {}", self.action_identifiers) + if order_identifier in self.action_identifiers: + logger.debug("Order identifier found in {}", order_identifier) return True diff --git a/findmyorder/main.py b/findmyorder/main.py index 57c3374d..04226d0b 100644 --- a/findmyorder/main.py +++ b/findmyorder/main.py @@ -51,7 +51,7 @@ def __init__( self.clients = [] # Create a client for each client in settings.myllm for name, client_config in settings.findmyorder.items(): - logger.debug("client_config: {}", client_config) + # logger.debug("client_config: {}", client_config) # Skip template and empty string client names if name in ["", "template"] or not client_config.get("enabled"): continue @@ -60,7 +60,7 @@ def __init__( logger.debug("Creating FMO parser {}", name) client = self._create_client(**client_config, name=name) # If the client has a valid client attribute, append it to the list - if client and getattr(client, "parser", None): + if client and getattr(client, "client", None): self.clients.append(client) except Exception as e: # Log the error if the client fails to be created @@ -108,7 +108,7 @@ def _create_client(self, **kwargs): """ library = kwargs.get("parser_library", "standard") client_class = self.client_classes.get(f"{library.capitalize()}Handler") - logger.debug(f"Creating {library} client with {kwargs} and {client_class}") + # logger.debug(f"Creating {library} client with {kwargs} and {client_class}") if client_class is None: logger.error(f"library {library} not supported") return None @@ -161,20 +161,38 @@ async def search(self, message: str) -> bool: """ for client in self.clients: + logger.debug("Searching with client: {}", client) if await client.search(message): return True return False + async def identify_order(self, message: str) -> bool: + """ + Search an order. + + Args: + message (str): Message + + Returns: + bool + + """ + results = [] + for client in self.clients: + result = await client.identify_order(message) + results.append(result) + return results + async def get_order( self, - msg: str, + message: str, ): """ Get an order from a message. The message can be an order or an order identifier Args: - msg (str): Message + message (str): Message Returns: dict @@ -182,6 +200,6 @@ async def get_order( """ results = [] for client in self.clients: - result = await client.get_order(msg) + result = await client.get_order(message) results.append(result) return results