cmallwitz / Financials-Extension

Extension for LibreOffice Calc to access stock market data
Other
137 stars 17 forks source link

GETHISTORIC not working for AAPL for recent dates using YAHOO #72

Closed khorton closed 1 year ago

khorton commented 1 year ago

=GETHISTORIC("AAPL",91,DATE(2022,12,19),"yahoo") results in

Date before 2000 '2022-12-19'

Much older dates work fine, as do many other tickers.

I'm running Financial-Extensions 3.2.1 in Libreoffice 7.4.3.2 on macOS 13.1 Ventura. I'm getting the same issue on two computers.

cmallwitz commented 1 year ago

I think that could be a new, previously unreported issue - some edge case handling for previous day...

Having said that, I wonder what Yahoo actually wants to tell us with the historic data for AAPL - it is afternoon in your location (correct ?), NY stock exchange is still open but Yahoo already reports "historic" data for today Dec 20 with a Close and Adj Close price.

cmallwitz commented 1 year ago

Ah - when updating the historic data URL - the row for today is actually updating...

khorton commented 1 year ago

The problematic dates for AAPL go back to 2022-08-20, at least at this moment. 2022-08-19 works. 2022-08-20 and later don't work. I see the same issue with ^GSPC and MSFT. TSLA and AMZN work correctly.

cmallwitz commented 1 year ago

Could you clarify "problem dates" - when you are not getting data, are you getting no value or "Date before 2000" or a mix (if mix, could you provide some examples)?

khorton commented 1 year ago

For every date from 2022-08-20 to today (2022-12-20), I'm getting "Date before 2000" for AAPL, MSFT and ^GSPC.

khorton commented 1 year ago

Hmm. Something has changed. I was getting the issue on both my computers. But now, it is working correctly on one computer, and not working on the other. So, odds are it is my local issue, and not a code issue. I'll report back once I find the smoking gun.

khorton commented 1 year ago

Where would I find a log giving sufficient detail to hopefully learn why this GETHISTORIC call is failing in one user account on one of my computers?

cmallwitz commented 1 year ago

Usually anything extension related would be in the .financials-extension folder in your HOME directory. Unexpected exceptions would go to the extension.log file and a trace of all calls mad to the extension are in trace.log

It would be interesting what the difference is between your two computers: any difference in regional settings/language e.g. data or time format used by default (think about US vs European data formats when it comes do month/date order or stuff like 12 vs 24 hours format). I'm not sure if it does but it could have an impact when the Python code of the extension is executed and lead to different results.

khorton commented 1 year ago

The regional settings, language, date/time formats are identical between the two computers.

The last entry relating to AAPL in extension.log is:

2022-12-20 19:41:24,391 financials_yahoo ERROR BaseException ticker=AAPL datacode=Datacode.LAST_PRICE
Traceback (most recent call last):
  File "/Users/kwh/Library/Application Support/LibreOffice/4/user/uno_packages/cache/uno_packages/lu83399381lqs.tmp_/Financials-Extension.oxt/financials_yahoo.py", line 166, in getRealtimeSummary
    text = self.urlopen(url, redirect=True, data=None, headers=None, cookies=self.get_cookies())
  File "/Users/kwh/Library/Application Support/LibreOffice/4/user/uno_packages/cache/uno_packages/lu83399381lqs.tmp_/Financials-Extension.oxt/baseclient.py", line 141, in urlopen
    self.response = self.request('POST' if data else 'GET', url, data, headers, cookies, **kwargs)
  File "/Users/kwh/Library/Application Support/LibreOffice/4/user/uno_packages/cache/uno_packages/lu83399381lqs.tmp_/Financials-Extension.oxt/baseclient.py", line 125, in request
    connection.request(method, '/' + path, data, _headers)
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/Current/lib/python3.8/http/client.py", line 1256, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/Current/lib/python3.8/http/client.py", line 1302, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/Current/lib/python3.8/http/client.py", line 1251, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/Current/lib/python3.8/http/client.py", line 1011, in _send_output
    self.send(msg)
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/Current/lib/python3.8/http/client.py", line 951, in send
    self.connect()
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/Current/lib/python3.8/http/client.py", line 1418, in connect
    super().connect()
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/Current/lib/python3.8/http/client.py", line 922, in connect
    self.sock = self._create_connection(
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/Current/lib/python3.8/socket.py", line 787, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/Applications/LibreOffice.app/Contents/Frameworks/LibreOfficePython.framework/Versions/Current/lib/python3.8/socket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known

============================ trace.log just shows things like:

2022-12-21 20:15:08.059048 getHistoric *args=('AAPL', 91.0, 44798.0, 'yahoo') r='Date before 2000 '2022-08-25'' 0.611 ms

khorton commented 1 year ago

I've got Good News, and Bad News.

The Good News is that GETHISTORIC is now working for all tickers that had previously been problematic.

The Bad News is that I'm not sure what the fix was. I did a detailed comparison of the various settings files that are present on the two computers. The problematic computer had preferences files for StarOffice, OpenOffice and NeoOffice, which I deleted. I reset the Date & Time and Languages and Regions settings. I deleted all the files in .financial-extensions related to the problematic tickers. And I logged out and in of my user account few times during this process. In the end, everything was working correctly. Sorry for the noise