Skip to content

Commit

Permalink
♻️
Browse files Browse the repository at this point in the history
  • Loading branch information
mraniki committed Jul 5, 2024
1 parent 41515cf commit 8821d78
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
10 changes: 6 additions & 4 deletions findmyorder/handler/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
30 changes: 24 additions & 6 deletions findmyorder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -161,27 +161,45 @@ 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
"""
results = []
for client in self.clients:
result = await client.get_order(msg)
result = await client.get_order(message)
results.append(result)
return results

0 comments on commit 8821d78

Please sign in to comment.