https://github.com/dblock/google-finance-ruby-client
Google Finance web API ruby client with support for retrieving stock quotes and historical prices.
https://github.com/dblock/google-finance-ruby-client
google google-finance ruby stock-prices stock-quotes stocks yahoo-finance yahoo-finance-api
Last synced: 8 months ago
JSON representation
Google Finance web API ruby client with support for retrieving stock quotes and historical prices.
- Host: GitHub
- URL: https://github.com/dblock/google-finance-ruby-client
- Owner: dblock
- License: mit
- Archived: true
- Created: 2017-12-02T16:15:50.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-10-11T01:35:47.000Z (almost 5 years ago)
- Last Synced: 2025-01-19T00:59:07.185Z (9 months ago)
- Topics: google, google-finance, ruby, stock-prices, stock-quotes, stocks, yahoo-finance, yahoo-finance-api
- Language: Ruby
- Homepage:
- Size: 204 KB
- Stars: 9
- Watchers: 3
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
Google Finance Ruby Client
==========================[](https://badge.fury.io/rb/google-finance-ruby-client)
[](https://travis-ci.org/dblock/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](https://groups.google.com/forum/#!msg/google-finance-apis/O8fjsgnamHE/-ZKSjif4yDIJ)._
## 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](lib/google-finance/api/index.rb).
```ruby
quote = GoogleFinance::Quote.get('MSFT')quote.last_trade_price # 84.26
quote.change # 0.09
quote.change_in_percent # 0.11
quote.change_in_percent_s # "+0.11%"
```See [quote.rb](lib/google-finance/quote.rb) for returned fields.
If a symbol cannot be found a [GoogleFinance::Errors::SymbolNotFound](lib/google-finance/errors/symbol_not_found_error.rb) is raised.
### Get Multiple Quotes
Searches for a ticker or tickers, then fetches each quote.
```ruby
quotes = GoogleFinance::Quotes.search('MSFT', 'AB')quotes.size # 2
quotes[0] # GoogleFinance::Quote.get('MSFT')
quotes[1] # GoogleFinance::Quote.get('AB')
```If one of the symbols cannot be found a [GoogleFinance::Errors::SymbolsNotFound](lib/google-finance/errors/symbols_not_found_error.rb) is raised.
### Get Price History
#### Daily Price History
Fetches price history for a ticker via [https://finance.google.com/finance/historical](lib/google-finance/api/historical.rb).
```ruby
prices = GoogleFinance::History.get('MSFT')# prices for the last year of open markets
prices.count # 251# prices appear in reverse chronological order
prices.first # # high=86.05 low=85.5 open=85.63 volume=18717406>
prices[1] # # high=85.93 low=85.55 open=85.9 volume=10594344>
```If a symbol cannot be found a [GoogleFinance::Errors::SymbolNotFound](lib/google-finance/errors/symbol_not_found_error.rb) is raised.
The following options are supported.
* `start_date`: date to start retrieving from
* `end_date`: date to retrieve data up toRetrieve prices in the first trading week of 2016. No trading on the week-end or during holidays.
```ruby
prices = GoogleFinance::History.get('MSFT', start_date: Date.parse('2016-01-03'), end_date: Date.parse('2016-01-10'))prices.count # 5
prices.first # # high=53.28 low=52.15 open=52.37 volume=48753969>
```#### Intraday Price History
Fetches price history, including at intraday intervals, for a ticker via [https://finance.google.com/finance/getprices](lib/google-finance/api/get_prices.rb).
```ruby
prices = GoogleFinance::Prices.get('MSFT')prices.exchange # NASDAQ
# prices for the last month of open markets
prices.count # 21# prices appear in reverse chronological order
prices.last #
prices[-2] #
```See [price.rb](lib/google-finance/price.rb) for returned fields.
If a symbol cannot be found a [GoogleFinance::Errors::SymbolNotFound](lib/google-finance/errors/symbol_not_found_error.rb) is raised.
The following options are supported.
* `exchange`: stock exchange symbol on which stock is traded, eg. `NASDAQ`
* `interval`: interval size in seconds
* `period`: period, a number followed by `d` (days) or `Y` (years)
* `fields`: array of data to return
* `date`: timestamp
* `open`: price at market open
* `close`: price at market close
* `volume`: volume
* `low`: low price
* `high`: high priceRetrieve intraday prices in 1 hour intervals.
```ruby
prices = GoogleFinance::Prices.get('GOOG', interval: 60 * 60, period: '1d')prices.count # 7
prices # array of GoogleFinance::Price, date=2017-12-29 10:00AM, 11:00AM, etc.
```Retrieve only prices at market close.
```ruby
prices = GoogleFinance::Prices.get('GOOG', fields: [:days, :close])prices.first # #
```## Contributing
See [CONTRIBUTING](CONTRIBUTING.md).
## Copyright and License
Copyright (c) 2017, [Daniel Doubrovkine](https://twitter.com/dblockdotorg) and [Contributors](CHANGELOG.md).
This project is licensed under the [MIT License](LICENSE.md).