The other evening a friend mentioned on gtalk that he was playing around with ystockquote, a python library that provides a nice interface to Yahoo! Finance data.
Needless to say, I thought, "Hey! I'd like to check that out too." So next thing I know I'm running
pip install ystockquote, pop open a python shell, and
import ystockquote as ys.
I run a few individual queries such as
ys.get_book_value('GOOG') which all seem to work well enough. Then I tried
ys.get_all('GOOG'). That's when I noticed something wasn't right.
>>> import ystockquote as ys >>> ys.get_all('GOOG')['book_value'] '36.746' >>> ys.get_book_value('GOOG') '248.353' >>>
As you can see above, the value returned from get_all() doesn't equal the individual call. Given that the project is open source and hosted on GitHub, I decided to take a look.
Modifying the Library
I viewed the ystockquote issues page on github and noticed that this issue was reported as Issue #12, and had yet to be resolved. The following is the approximate series of steps that I took to resolve the issue.
Setup a directory to work on the project:
mkdir ystockquote; cd ystockquote git init git remote add origin http://github.com/rarmknecht/ystockquote.git git pull git checkout master
I then created a branch that contained my fixes, called "Issue12-Fix"
git branch Issue12-Fix git push origin Issue12-Fix git checkout Issue12-Fix
Now that I was working in a branch to fix the issue I started in on troubleshooting. By manually calling
ys._request(symbol,id)I was able to determine that there was a typo in the listing of ids, and that a few of the ids potentially return values with commas in them. Changes Made
After believing that I found the issue, I updated the unit tests to confirm that get_all was functioning. Sure enough, the updated test failed for the original code and passed for my updated code.
self.assertEqual(all_info['dividend_yield'], ystockquote.get_dividend_yield(symbol)) self.assertEqual(all_info['fifty_sma'], ystockquote.get_50_sma(symbol)) self.assertEqual(all_info['company_name'], ystockquote.get_company_name(symbol)) self.assertEqual(all_info['book_value'], ystockquote.get_book_value(symbol))
I then merged the resolved branch back into the master branch on my personal fork:
git checkout master git pull origin master git merge Issue12-Fix git push origin master
Finally, I created a pull request to inform the original author that a resolution has been created and is available to be merged into the official branch of the library.
So that's all there was to it. Now I'll have to wait and see if the original author accepts my modifications. If not, feel free to pull the forked version from my repo.
>>> import ystockquote as ys >>> ys.get_all('GOOG')['book_value'] '248.353' >>> ys.get_book_value('GOOG') '248.353' >>>