From 593c755e68eccaa318f18c8bb96656f87c4b508a Mon Sep 17 00:00:00 2001 From: Vishal Grover Date: Fri, 25 Oct 2024 17:39:47 +0100 Subject: [PATCH 1/3] Amended IB connection method to catch all exceptions, log a critical error message and re-raise. Changed ib_client.py error_handler to log all broker_errors as critical rather than warnings --- sysbrokers/IB/client/ib_client.py | 2 +- sysbrokers/IB/ib_connection.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/sysbrokers/IB/client/ib_client.py b/sysbrokers/IB/client/ib_client.py index 963d4ad78e..f57de29949 100644 --- a/sysbrokers/IB/client/ib_client.py +++ b/sysbrokers/IB/client/ib_client.py @@ -130,7 +130,7 @@ def error_handler( self.broker_message(msg=msg, log=self.log) def broker_error(self, msg, log, myerror_type): - log.warning(msg) + log.critical(msg) def broker_message(self, log, msg): log.debug(msg) diff --git a/sysbrokers/IB/ib_connection.py b/sysbrokers/IB/ib_connection.py index b72b226aa2..94cbcb39cc 100644 --- a/sysbrokers/IB/ib_connection.py +++ b/sysbrokers/IB/ib_connection.py @@ -61,9 +61,16 @@ def __init__( # You can pass a client id yourself, or let IB find one - self._init_connection( - ipaddress=ipaddress, port=port, client_id=client_id, account=account - ) + try: + self._init_connection( + ipaddress=ipaddress, port=port, client_id=client_id, account=account + ) + except Exception as e: + # Log all exceptions generated during connection as critical error. + # Under the default production setup this should send an email. + # Error is reraised as we can't really continue and user intervention is required + self.log.critical(f"IB connection falied with exception - {e}, connection aborted.") + raise def _init_connection( self, ipaddress: str, port: int, client_id: int, account=arg_not_supplied From 7b91cb7d5eec980e53e96f2bd572ee61de6ba7e1 Mon Sep 17 00:00:00 2001 From: Vishal Grover Date: Fri, 25 Oct 2024 17:42:01 +0100 Subject: [PATCH 2/3] running black --- sysbrokers/IB/ib_connection.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sysbrokers/IB/ib_connection.py b/sysbrokers/IB/ib_connection.py index 94cbcb39cc..9045fea959 100644 --- a/sysbrokers/IB/ib_connection.py +++ b/sysbrokers/IB/ib_connection.py @@ -69,7 +69,9 @@ def __init__( # Log all exceptions generated during connection as critical error. # Under the default production setup this should send an email. # Error is reraised as we can't really continue and user intervention is required - self.log.critical(f"IB connection falied with exception - {e}, connection aborted.") + self.log.critical( + f"IB connection falied with exception - {e}, connection aborted." + ) raise def _init_connection( From abf2c483a66b7fab53e826bdf7d27d1770bd3863 Mon Sep 17 00:00:00 2001 From: Vishal Grover Date: Sat, 26 Oct 2024 12:23:28 +0100 Subject: [PATCH 3/3] Reverted the change to ib_client.py as it could lead to large volume of emails being generated --- sysbrokers/IB/client/ib_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sysbrokers/IB/client/ib_client.py b/sysbrokers/IB/client/ib_client.py index f57de29949..963d4ad78e 100644 --- a/sysbrokers/IB/client/ib_client.py +++ b/sysbrokers/IB/client/ib_client.py @@ -130,7 +130,7 @@ def error_handler( self.broker_message(msg=msg, log=self.log) def broker_error(self, msg, log, myerror_type): - log.critical(msg) + log.warning(msg) def broker_message(self, log, msg): log.debug(msg)