Skip to content

Conversation

@mbafford
Copy link
Contributor

For a mutual fund for today, Yahoo API returns a null for the most recent price entry in the price array. A timestamps is present, but the price values are null:

e.g.:
[9.6899995803833,9.710000038146973,9.6899995803833,null]

The current code anticipates the response potentially returning a price earlier than the date queried, so this fix just filters out the null entries and returns what's left, even if earlier than the queried date.

e.g. from:
https://query1.finance.yahoo.com/v8/finance/chart/FTIHX?period1=1645650000&period2=1646082000&interval=1d&lang=en-US&corsDomain=finance.yahoo.com&.tsrc=finance

returns:

{"chart":{"result":[{"meta":{"currency":"USD","symbol":"FTIHX","exchangeName":"NAS","instrumentType":"MUTUALFUND","firstTradeDate":1466083800,"regularMarketTime":1646053576,"gmtoffset":-18000,"timezone":"EST","exchangeTimezoneName":"America/New_York","regularMarketPrice":13.63,"chartPreviousClose":13.56,"priceHint":2,"currentTradingPeriod":{"pre":{"timezone":"EST","start":1646038800,"end":1646058600,"gmtoffset":-18000},"regular":{"timezone":"EST","start":1646058600,"end":1646082000,"gmtoffset":-18000},"post":{"timezone":"EST","start":1646082000,"end":1646096400,"gmtoffset":-18000}},"dataGranularity":"1d","range":"","validRanges":["1mo","3mo","6mo","ytd","1y","2y","5y","10y","max"]},
"timestamp":[1645626600,1645713000,1645799400,1646058600],
"indicators":{"quote":[{
"close":[13.5600004196167,13.34000015258789,13.630000114440918,null],
"low":[13.5600004196167,13.34000015258789,13.630000114440918,null],
"open":[13.5600004196167,13.34000015258789,13.630000114440918,null],
"high":[13.5600004196167,13.34000015258789,13.630000114440918,null]
,"volume":[0,0,0,null]}],"adjclose":[{"adjclose":[13.5600004196167,13.34000015258789,13.630000114440918,null]}]}}],"error":null}}

@mbafford
Copy link
Contributor Author

mbafford commented Mar 1, 2022

Duplicate fix in code as #66 - this PR includes a test for this case.

@maxromanovsky
Copy link

@blais I've been experiencing this issue recently, and this fix helped me. Any chance to get it merged?

@blais blais merged commit 41576e2 into beancount:master Dec 31, 2023
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.

3 participants