Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1428 ib critical errors #1429

Merged

Conversation

vishalg
Copy link

@vishalg vishalg commented Oct 25, 2024

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 as warnings.

Vishal Grover added 2 commits October 25, 2024 17:39
…error

message and re-raise.
Changed ib_client.py error_handler to log all broker_errors as critical
rather than warnings
@bug-or-feature
Copy link
Collaborator

@vishalg have you tested this? I'm a bit concerned about the change to ib_client.py - if a large bunch of critical errors happen in a short burst, triggering lots of emails, it CAN look like spam to an SMTP server. This bit me once before, my own mail server got blacklisted and it was a pain to unwind. Ideally we would have an email sending queue, or a system to throttle a high number of identical messages in a short time.

@vishalg
Copy link
Author

vishalg commented Oct 26, 2024

I have not had an such an experience yet, but I imagine it can cause an issue. i'll revert that change but we should still log the IB connection errors as critical. This happens to me quite a lot - I run TWS in docker with 2FA enabled and sometimes miss the notification when TWS gets restarted on Sundays.

@vishalg
Copy link
Author

vishalg commented Oct 26, 2024

I think we should change the PstSMTPHandler in syslogging.handlers to use email_via_db_interface rather than the send_msg directly. If you agree, I can make the changes and update

@bug-or-feature bug-or-feature merged commit 4d89b98 into robcarver17:develop Oct 26, 2024
2 checks passed
@bug-or-feature
Copy link
Collaborator

bug-or-feature commented Oct 26, 2024

I think it would be better to replace PstSMTPHandler with one with a queue or buffer. I'm pretty sure I saw some code for one already. To be honest I should have done it at the time of the log rewrite. I'll do this, just let me test for a few days next week

@vishalg
Copy link
Author

vishalg commented Oct 26, 2024

Yeah, that makes sense. Logging handlers don't currently have access to the data pipeline objects though - if the queue is held in memory messages can get lost and we'd need a way to persist to disk. I'll have a stab at it and submit a new request along with a change to the way SMTP connections are handled currently.

@bug-or-feature
Copy link
Collaborator

@vishalg Digging into this a bit more, I don't think the log records coming from ib_client.py should be critical. Many of the kind of messages that are supposed to be handled there are things like "price out of range", "modify order failed", "order rejected". Those are not critical situations. I do think they should be error rather than warning. Admittedly, "can't connect" is in there too - maybe there should be some modified logic to handle that better? I'm not sure, I don't know this code very well. But, if you're really sure you want an email for any of those types of problems, then I think a better solution would use a custom logging config

@vishalg
Copy link
Author

vishalg commented Oct 27, 2024

That was my initial thoughts as well, but looking at IB_ERROR_TYPES (sysbrokers.IB.client.ib_client.py) a majority of them seem to be related to orders - although I am not sure to what extent these definitely need user attention.

There may be a case for augmenting IB_ERROR_TYPES with severity level and then deal with them accordingly.

I will park this for now until I have had more experience running the system on a live account and collected enough instances of when and how these messages are being generated.

@bug-or-feature
Copy link
Collaborator

Agreed, I'll do same. Here's the full list of messages from IB:

https://ibkrcampus.com/campus/ibkr-api-page/twsapi-doc/#error-handling

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants