Google Finance Ruby Client
A Ruby client for the undocumented Google Finance web API. Supports stock quotes and historical prices. Attempts to make sense of, coerce and structure the data.
IANAL, but do note that if your application is for public consumption, using the Google Finance API seems to be against Google's terms of service.
Installation
Add to Gemfile.
gem 'google-finance-ruby-client'
Run bundle install
.
Usage
Get a Quote
Fetches stock quotes via https://finance.google.com/finance.
quote = GoogleFinance::Quote.get('MSFT')
quote.last_trade_price
quote.change
quote.change_in_percent
quote.change_in_percent_s
See quote.rb for returned fields.
If a symbol cannot be found a GoogleFinance::Errors::SymbolNotFound is raised.
Get Multiple Quotes
Searches for a ticker or tickers, then fetches each quote.
quotes = GoogleFinance::Quotes.search('MSFT', 'AB')
quotes.size
quotes[0]
quotes[1]
If one of the symbols cannot be found a GoogleFinance::Errors::SymbolsNotFound is raised.
Get Price History
Daily Price History
Fetches price history for a ticker via https://finance.google.com/finance/historical.
prices = GoogleFinance::History.get('MSFT')
prices.count
prices.first
prices[1]
If a symbol cannot be found a GoogleFinance::Errors::SymbolNotFound is raised.
The following options are supported.
start_date
: date to start retrieving fromend_date
: date to retrieve data up to
Retrieve prices in the first trading week of 2016. No trading on the week-end or during holidays.
prices = GoogleFinance::History.get('MSFT', start_date: Date.parse('2016-01-03'), end_date: Date.parse('2016-01-10'))
prices.count
prices.first
Intraday Price History
Fetches price history, including at intraday intervals, for a ticker via https://finance.google.com/finance/getprices.
prices = GoogleFinance::Prices.get('MSFT')
prices.exchange
prices.count
prices.last #<GoogleFinance::Price close=85.71 date=2017-12-27 16:00:00 -0500 high=85.98 low=85.215 open=85.65 volume=14678025>
prices[-2] #<GoogleFinance::Price close=85.4 date=2017-12-26 16:00:00 -0500 high=85.5346 low=85.03 open=85.31 volume=9891237>
See price.rb for returned fields.
If a symbol cannot be found a GoogleFinance::Errors::SymbolNotFound is raised.
The following options are supported.
exchange
: stock exchange symbol on which stock is traded, eg. NASDAQ
interval
: interval size in secondsperiod
: period, a number followed by d
(days) or Y
(years)fields
: array of data to return
date
: timestampopen
: price at market openclose
: price at market closevolume
: volumelow
: low pricehigh
: high price
Retrieve intraday prices in 1 hour intervals.
prices = GoogleFinance::Prices.get('GOOG', interval: 60 * 60, period: '1d')
prices.count
prices
Retrieve only prices at market close.
prices = GoogleFinance::Prices.get('GOOG', fields: [:days, :close])
prices.first
Contributing
See CONTRIBUTING.
Copyright and License
Copyright (c) 2017, Daniel Doubrovkine and Contributors.
This project is licensed under the MIT License.