Open stark4x opened 7 months ago
Thanks @stark4x for opening this issue!
For COLLABORATOR only :
To add labels, comment on the issue
/label add label1,label2,label3
To remove labels, comment on the issue
/label remove label1,label2,label3
First issue by @stark4x
Issues Details of @stark4x in ibkr-options-volatility-trading : | OPEN | CLOSED | TOTAL |
---|---|---|---|
1 | 0 | 1 |
The solution involves addressing multiple issues across different files to ensure robust error handling, proper instantiation of notifiers, and correct execution of the MarketWatcher engine. The plan includes fixing typos, enhancing error handling for SSL-related issues, ensuring that the YahooFinancials
library is correctly handling SSL connections, and improving logging to provide better feedback during execution.
The bug seems to be caused by an SSLError(SSLZeroReturnError)
which indicates that the SSL/TLS connection has been closed unexpectedly. This error is likely occurring during an HTTP request made by the YahooFinancials
library, which is used to fetch financial data. The lack of comprehensive error handling and logging in the market_watcher_cli.py
and common.py
files may be obscuring the underlying problem, making it difficult to diagnose and resolve the issue.
To address the issues, the following code changes are recommended:
In src/market_watcher/market_watcher_cli.py
, fix the typo in the function name:
# Before
def get_terget_stocks():
# After
def get_target_stocks():
Add error handling for SSLError
in src/market_watcher/market_watcher_cli.py
:
try:
# Existing code to start MarketWatcher engine
except SSLError as ssl_error:
# Log the SSL error for further investigation
logger.error(f"SSL error occurred: {ssl_error}")
Ensure that the YahooFinancials
library is correctly handling SSL connections. If the library is not handling it, consider wrapping its calls in try-except blocks to handle the SSLError
in src/market_watcher/common.py
:
from requests.exceptions import SSLError
try:
except SSLError as ssl_error:
4. Improve logging throughout the `start` command in `src/market_watcher/market_watcher_cli.py` to provide feedback on the progress and any potential issues encountered.
5. In `src/market_watcher/notifier.py`, replace assertions with proper error handling:
```python
response = requests.post(self.webhook_url, json=message_payload)
if response.status_code != 200 or response.text != "ok":
# Log the error instead of asserting
logger.error(f"Failed to send Slack message: {response.text}")
To replicate the bug, one would need to run the MarketWatcher engine and trigger an SSL connection issue. This could be done by attempting to fetch financial data using the YahooFinancials
library over an SSL connection that is prone to being closed unexpectedly. The exact replication steps would depend on the specific environment and external factors affecting SSL connections.
To resolve the bug, the following tasks should be carried out:
YahooFinancials
library to the latest version or ensure it is correctly handling SSL connections. If the issue persists, consider using a different financial data API or library.Click here to create a Pull Request with the proposed solution
Files used for this task:
Not Found
Not Found
Not Found
Starting MarketWatcher... MarketWatcher started. Reading target stocks from file: src/market_watcher/research/target_stocks.yaml Instantiating email notifier... Instantiating slack notifier... Instantiating MarketWatcher and running the engine. WARNING:urllib3.connectionpool:Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLZeroReturnError(6, 'TLS/SSL connection has been closed (EOF) (_ssl.c:1135)'))': /