A gem for interacting with the Google Finance API
gem install gmoney
GMoney::GFSession.login('google username', 'password')
Reading > portfolios = GMoney::Portfolio.all #returns all of a user's portfolios > portfolio = GMoney::Portfolio.find(9) #returns a specific portfolio > positions = portfolio.positions #returns an Array of the Positions held within a given portfolio Creating > portfolio = GMoney::Portfolio.new > portfolio.title = "My New Portfolio" > portfolio.save #returns portfolio object Updating > portfolio = GMoney::Portfolio.find 9 > portfolio.title = "My Updated Portfolio Title" > portfolio.save #returns portfolio object Deleting > GMoney::Portfolio.delete 2 or > portfolio = GMoney::Portfolio.find 2 > portfolio.delete #call delete on an instance of a portfolio
Reading > positions = GMoney::Position.find(9) #returns all of a user's positions within a given portfolio, i.e. Portfolio "9" > position = GMoney::Position.find("9/NASDAQ:GOOG") #returns a specific position within a given portfolio > transactions = position.transactions #returns an Array of the Transactions within a given position Creating/Updating Positions are created/updated via transactions Deleting > GMoney::Position.delete '2/NASDAQ:GOOG' or > position = GMoney::Position.find '2/NASDAQ:GOOG' > position.delete #call delete on an instance of a position
Reading > transactions = GMoney::Transaction.find("9/NASDAQ:GOOG") #returns all of a user's transactions within a given position > transaction = GMoney::Transaction.find("9/NASDAQ:GOOG/2") #returns a specific transaction within a given position Creating > transaction = GMoney::Transaction.new > transaction.portfolio = 9 #Must be a valid portfolio id > transaction.ticker = 'nyse:c' #Must be a valid ticker symbol > transaction.type = GMoney::BUY #Must be one of the following: Buy, Sell, Sell Short, Buy to Cover > transaction.save #returns transaction object Updating > transaction = GMoney::Transaction.find('9/NYSE:C/1') > transaction.shares = 50 > transaction.price = 3.50 > transaction.save #returns transaction object Note: While updating transactions it is not possible to change the portfolio or ticker property as these values are used by Google to identify specific transactions. Deleting > GMoney::Transaction.delete '2/NASDAQ:GOOG/1' or > transaction = GMoney::Transaction.find '2/NASDAQ:GOOG/1' > transaction.delete #call delete on an instance of a transaction
The following methods: Portfolio.all Portfolio.find portfolio.positions #where portfolio is an instance of the Portfolio class Position.find position.transactions #where position is an instance of the Position class Transaction.find all take a hash as an optional last parameter. Valid values for this hash are: * :returns - By default Google does not return a comprehensive list of returns data. Set this parameter to true to access this information. * :refresh - GMoney caches the data returned from Google by default. Set :refresh => true if you would like to get the latest data. * :eager - GMoney lazily loads children data (i.e. positions for a given Portfolio). If you would like to load all of this data at once set :eager => true
There are still some rough edges. Feedback is appreciated.
(The MIT License)
Copyright © 2010 Justin Spradlin
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.