Contributing to ystockquote on GitHub

The Trigger

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.

  1. First, I forked the project on GitHub to my own repository so that I could edit the code and push my changes up to the GitHub server

  2. 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
    
  3. 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
    
  4. 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

  5. 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))
    
  6. 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
    
  7. 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.

Wrap Up

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'
>>>