Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tyrauber/stock_quote
A ruby gem that retrieves stock quotes from IEX
https://github.com/tyrauber/stock_quote
Last synced: 12 days ago
JSON representation
A ruby gem that retrieves stock quotes from IEX
- Host: GitHub
- URL: https://github.com/tyrauber/stock_quote
- Owner: tyrauber
- License: mit
- Created: 2011-11-17T04:29:58.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2024-01-26T14:52:02.000Z (10 months ago)
- Last Synced: 2024-10-14T11:54:51.663Z (about 1 month ago)
- Language: Ruby
- Homepage:
- Size: 111 KB
- Stars: 210
- Watchers: 17
- Forks: 55
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# stock_quote
Real-time, stock data and historical pricing. Data provided by [IEXCLOUD.IO](https://iexcloud.io/). An [API KEY](https://iexcloud.io/cloud-login#/register/) is now required.
# Update
On August 29, 2023, it was reported that ["IEX Cloud Has Changed their Pricing Structure" (#70)](/../../issues/70), and will no longer be allowing free API access. Additionally, the API endpoint this library currently uses will now cost $1500/month to access. Please be aware of [the pricing changes](https://iexcloud.io/pricing) and direct all related inquires to [IEX support](https://iexcloud.io/console/support).
## Installation
To install the 'stock_quote' ruby gem:
`gem install stock_quote`
## Gem Configuration
To use the gem in your Rails Application, include it in your Gemfile:
`gem "stock_quote"`, '~> 3.0.0'
## Initialization
To globally initialize StockQuote with a valid API_KEY:
`StockQuote::Stock.new(api_key: YOUR_API_KEY)`
You can also supply api_key as an attribute in any StockQuote::Stock method.
### StockQuote::Stock.quote(symbol)
Quote is the primary method, returning a StockQuote::Stock instance, including the following attributes (new in v2.0.0).
`symbol, company_name, primary_exchange, sector, calculation_price, open, open_time, close, close_time, high, low, latest_price, latest_source, latest_time, latest_update, latest_volume, iex_realtime_price, iex_realtime_size, iex_last_updated, delayed_price, delayed_price_time, previous_close, change, change_percent, iex_market_percent, iex_volume, avg_total_volume, iex_bid_price, iex_bid_size, iex_ask_price, iex_ask_size, market_cap, pe_ratio, week52_high, week52_low, ytd_change, chart`
You can get a current quote with the following syntax:
`stock = StockQuote::Stock.quote("symbol")`
Where symbol equals the company stock symbol you want a quote for. For example, "aapl" for Apple, Inc.
You may search for multiple stocks by separating symbols with a comma (or array). For example:
`stocks = StockQuote::Stock.quote("aapl,tsla")`
These queries will return a Stock object or an array of Stock objects which you may iterate through.
Note: You can receive a raw json hash response with the following syntax:
`stocks = StockQuote::Stock.raw_quote("aapl,tsla")`
The raw_ method is available on all supported methods.
### Other Methods
The IEX API is quite extensive and well documented.
V3.0.0 of stock_quote mirrors the IEXCLOUD.IO API:
* [book](https://iexcloud.io/docs/api/#book)
* [chart](https://iexcloud.io/docs/api/#historical-prices)
* [company](https://iexcloud.io/docs/api/#company)
* [delayed_quote](https://iexcloud.io/docs/api/#delayed-quote)
* [dividends](https://iexcloud.io/docs/api/#dividends)
* [earnings](https://iexcloud.io/docs/api/#earnings)
* [financials](https://iexcloud.io/docs/api/#financials)
* [stats](https://iexcloud.io/docs/api/#key-stats)
* [logo](https://iexcloud.io/docs/api/#logo)
* [news](https://iexcloud.io/docs/api/#news)
* [ohlc](https://iexcloud.io/docs/api/#ohlc)
* [peers](https://iexcloud.io/docs/api/#peers)
* [previous](https://iexcloud.io/docs/api/#previous)
* [price](https://iexcloud.io/docs/api/#price)
* [quote](https://iexcloud.io/docs/api/#quote)
* [relevant](https://iexcloud.io/docs/api/#relevant)
* [splits](https://iexcloud.io/docs/api/#splits)
* [volume_by_venue](https://iexcloud.io/docs/api/#volume-by-venue)All these methods are available on StockQuote::Stock.
For example:
```StockQuote::Stock.company('aapl')```
Retrieves company information.
For example:
```StockQuote::Stock.dividends('aapl')```
Retrieves dividend information.
Raw json hash responses are available for any of the methods by pre-fixing the method name with "raw__".
For example:
```StockQuote::Stock.raw_dividends('aapl')```
Retrieves raw dividend information.
### [batch](https://iextrading.com/developer/docs/#batch-requests)
Batch allows you to batch requests. All methods in stock_quote use batch under-the-hood.
Batch follows the syntax:
```StockQuote::Stock.batch(type, symbol, range)```
Where type can be multiple of the above methods and symbol can be an array of company symbols.
Range can be:
`5y, 2y, 1y, ytd, 6m, 3m, 1m, 1d`
And are applied to chart method.
## License
Copyright (c) 2019 Ty Rauber
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.