GithubHelp home page GithubHelp logo

stock_quote's Introduction

stock_quote

Real-time, stock data and historical pricing. Data provided by IEXCLOUD.IO. An API KEY is now required.

Update

On August 29, 2023, it was reported that "IEX Cloud Has Changed their Pricing Structure" (#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 and direct all related inquires to IEX 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:

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

stock_quote's People

Contributors

alexandrebp avatar cjavdev avatar dblock avatar drusepth avatar kharkivrem avatar lezoudali avatar markgandolfo avatar martinbjeldbak avatar tyrauber avatar umairjibran avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stock_quote's Issues

history api not working

I am getting invalid query error for the history api.

Please check and revert me about the correct usage.

Using Stock to represent both an Error and an actual quote

I think it would be best to break up the two cases. The Stock#initialize method currently is handling the result of json and setting the response code to either be 404 and the error code or its setting up all the attributes of the successful request. It occurs to me that these are two very separate responsibilities. We should add a class or struct for Error when interacting with api. And during the ::parse method we can either call a passed in error block or raise an Exception based on the API diagnostic results.

Thoughts? This will change the failure case of the API, but not the green pastures case.

Quotes now result in server errors

I'm not sure if Yahoo just changed their API, but logic that would previously retrieve quotes over a period of time is now returning server errors from Yahoo.

Example code:

irb(main):055:0> data = StockQuote::Stock.quote('GOOG', Time.now - 1.year, Time.now)
=> [
#<StockQuote::Stock:0x0055a50117b410 @response_code=200, @symbol="GOOG", @_html_="<HEAD>">, 
#<StockQuote::Stock:0x0055a50115eb30 @response_code=200, @symbol="GOOG", @_html_="<TITLE>Error</TITLE>">, 
#<StockQuote::Stock:0x0055a501152c18 @response_code=200, @symbol="GOOG", @_html_="</HEAD>">, 
#<StockQuote::Stock:0x0055a50113a398 @response_code=404, @no_data_message="Query returns no valid data">, 
#<StockQuote::Stock:0x0055a50113a230 @response_code=200, @symbol="GOOG", @_html_="<BODY BGCOLOR=\"white\" FGCOLOR=\"black\">">, 
#<StockQuote::Stock:0x0055a501129a48 @response_code=200, @symbol="GOOG", @_html_="<!-- status code : 404 -->">, 
#<StockQuote::Stock:0x0055a501101098 @response_code=200, @symbol="GOOG", @_html_="<!-- Error: GET -->">, 
#<StockQuote::Stock:0x0055a5010f9370 @response_code=200, @symbol="GOOG", @_html_="<!-- host machine: media-router6.prod.media.bf1.yahoo.com -->">, 
#<StockQuote::Stock:0x0055a5010edc28 @response_code=200, @symbol="GOOG", @_html_="<!-- timestamp: 1496865667.000 -->">, 
#<StockQuote::Stock:0x0055a5010da600 @response_code=200, @symbol="GOOG", @_html_="<!-- url: https://ichart.finance.yahoo.com/table.csv?a=5&b=7&e=7&g=d&c=2016&d=5&f=2017&s=GOOG-->">, 
#<StockQuote::Stock:0x0055a5010bdb68 @response_code=200, @symbol="GOOG", @_html_="<H1>Error</H1>">, 
#<StockQuote::Stock:0x0055a5010b17a0 @response_code=200, @symbol="GOOG", @_html_="<HR>">, 
#<StockQuote::Stock:0x0055a50109d228 @response_code=404, @no_data_message="Query returns no valid data">, 
#<StockQuote::Stock:0x0055a50109d138 @response_code=200, @symbol="GOOG", @_html_="<FONT FACE=\"Helvetica,Arial\"><B>">, 
#<StockQuote::Stock:0x0055a50108cd88 @response_code=200, @symbol="GOOG", @_html_="Description: Could not process this \"GET\" request.">, 
#<StockQuote::Stock:0x0055a501078630 @response_code=200, @symbol="GOOG", @_html_="</B></FONT>">, 
#<StockQuote::Stock:0x0055a501046ea0 @response_code=200, @symbol="GOOG", @_html_="<HR>">, 
#<StockQuote::Stock:0x0055a5010266f0 @response_code=200, @symbol="GOOG", @_html_="</BODY>">
]

.quote is returning an array of HTML error lines (instead of actual stock/quote data), which look like this when concatenated together:

irb(main):054:0> puts data.map { |s| s.instance_variable_get(:@_html_)}
<HEAD>
<TITLE>Error</TITLE>
</HEAD>

<BODY BGCOLOR="white" FGCOLOR="black">
<!-- status code : 404 -->
<!-- Error: GET -->
<!-- host machine: media-router46.prod.media.bf1.yahoo.com -->
<!-- timestamp: 1496865436.000 -->
<!-- url: https://ichart.finance.yahoo.com/table.csv?a=5&b=7&e=7&g=d&c=2016&d=5&f=2017&s=GOOG-->
<H1>Error</H1>
<HR>

<FONT FACE="Helvetica,Arial"><B>
Description: Could not process this "GET" request.
</B></FONT>
<HR>
</BODY>

The URL being requested )https://ichart.finance.yahoo.com/table.csv?a=5&b=7&e=7&g=d&c=2016&d=5&f=2017&s=GOOG) does indeed result in a 404 for me. Is this the correct URL to be fetching from? The same error appears when adjusting the date range (1 day, 30 days, and 90 days) from 1 year as well, and also has the same error when trying other ticker symbols also.

License missing from gemspec

Some companies will only use gems with a certain license.
The canonical and easy way to check is via the gemspec,

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Even for projects that already specify a license, including a license in your gemspec is a good practice, since it is easily
discoverable there without having to check the readme or for a license file.

For example, there is a License Finder gem to help companies ensure all gems they use
meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough
issue that even Bundler now generates gems with a default 'MIT' license.

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file),
github has created a license picker tool.

In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally
looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :).

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue and let me know. In either case, I'll follow up. Thanks!

p.s. I've written a blog post about this project

api doesn't work

Unfortunately since march 15th gem works very badly,
typing StockQuote::Stock.quote('GOOG') in rails console results error as follows:
2.4.1 :026 > StockQuote::Stock.quote('GOOG') JSON::ParserError: 765: unexpected token at '<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"><TITLE>302 Moved</TITLE></HEAD><BODY><H1>302 Moved</H1>Th'/BODY></HTML> moved<A HREF="https://finance.google.com/search?q=GOOG">here</A>.

The version of stock_quote on rubygems is not the same as here

I wanted to report this because I could not find out why #quote did not work. It turns out that even if the version number is the same, the code of the gem hosted on rubygems is not the same as here. It seems that some things are missing (like the #quote method).

Historical Data is missing attr accessors

When using the history method you return an array of StockQuote::Stocks, but these have data assigned which isn't accessible through attr_accessors.

Steps to reproduce

> history = StockQuote::Stock.history("CELG", "18-11-2013".to_date, "25-11-2013".to_date)
> stock = history.first
=> #<StockQuote::Stock:0x007f80e3877f60 @response_code=200, @date="2013-11-22", @open=161.0, @high=164.0, @low=160.45, @close=163.33, @volume=3620400.0, @adj_close=163.33, @symbol="'CELG'"> 
> stock.date
NoMethodError: undefined method `date' for #<StockQuote::Stock:0x007f80e3e2b510>

Work arounds

> stock.instance_variable_get("@date")

Fix

There are two ways I could think of fixing this.

  1. Chuck date, close, etc in @@fields
    • Issues:
      • Might cause confusion when these fields are nil after using the .stock method
      • All the defined attr accessors are nil for Stock after calling history
  2. Create a "HistoricalStock(s)" class which has those fields
    • Potential bonus: adding the success? method to the result of the history call, which, since an array is returned, gives a no method error if you check that too.

If you have a preference and no time to do it yourself, I could take a crack at fixing this bug. Otherwise I'll just use the instance_variable_get workaround.

Side note: thanks for this handy gem! :)

This version does not work

Hi,I'm currently using stock_quote version 2.0.0. I have installed the gem using "bundle install" and included the necessary code snippet as below. However, When the code is run from browser using "localhost:3000", the server terminates suddenly with the following error.

C:/tools/ruby25/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/log_subscriber.rb:98
Processing by HomeController#index as HTML Rendering home/index.html.erb within layouts/application Segmentation fault

The browser gives this error: "This site can't be reached. ERR_CONNECTION RESET."

Below is my code.

Segment code inside the gemFile

ruby '2.5.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.0'
gem 'mysql2', '>= 0.4.4', '< 0.6.0'
gem 'puma', '~> 3.11'
gem 'jquery-rails'
gem 'autoprefixer-rails'
gem 'bootstrap-sass', '~> 3.3.7'
gem 'bootstrap', '~> 4.0.0'
gem 'stock_quote', '~> 2.0.0'

home_controller.rb

class HomeController < ApplicationController
  def index
    #@stock = StockQuote::Stock.quote("goog")
  end
  def about
  end
end

Index.html.erb

<h1>STOCKER</h1>
<p>This is from Stocker page!</p>
<%= StockQuote::Stock.quote('aapl') %>

I'd appreciate your help on the above as I cannot proceed with the course from this point forward.

Thanks.

Deleted package detected

I'm a Cyber Security researcher and developer of PackjGuard [1] to address open-source software supply chain attacks.

Issue

During my research, I detected a deleted package in this repository.

Details

Specifically, the package stock_quote mentioned in file README at line 12 does not exist on the public RubyGems registry. A bad actor can hijack this package to propagate malicious code.

Impact

Not only your apps/services using https://github.com/tyrauber/stock_quote repo code are vulnerable to this attack, but the users of your open-source Github repo could also fall victim.

You could read more about such attacks here: https://medium.com/@alex.birsan/dependency-confusion-4a5d60fec610

Remediation

Please highlight this in file README and register a placeholder package for stock_quote on public RubyGems soon to remediate.

To automatically fix such issues in future, please install PackjGuard Github app [1].

Thanks!

  1. PackjGuard is a Github app that monitors your repos 24x7, detects vulnerable/malicious/risky open-source dependencies, and creates pull requests for auto remediation: https://github.com/marketplace/packjguard

ssl error accessing yahoo finance

[1] pry(main)> StockQuote::Stock.quote("aapl")
OpenSSL::SSL::SSLError: hostname "query.yahooapis.com" does not match the server certificate
from /home/hlandgar/.rvm/rubies/ruby-2.1.4/lib/ruby/2.1.0/openssl/ssl.rb:178:in `post_connection_check

Inspired google-finance-ruby-client

First, thanks for writing this gem. I stared using it in https://github.com/dblock/slack-market.

Then I started by trying to improve stock_quote (see #48 for example, then I wanted more consistent error handling, etc.), but gave up as the fetching of the data was just too messy between trying to deal with CSV, JSON and HTML returns in one place - it was easier to make a new gem from scratch. That's now https://github.com/dblock/google-finance-ruby-client. It uses Faraday and Hashie::Dash for base structures making things much cleaner.

Consider deprecating this gem and moving over to my rewrite, happy to put google-finance-ruby-client to an org, share maintenance, etc.

Incorrect quote for tickers that contains dot(.)

@stock = StockQuote::Stock.quote('TE.V', '11-03-2017')
should return quote for stock having ticker TE.V, But it returns the follows:

=> [#<StockQuote::Stock:0x007fc96e4a1098 @symbol="TE", @history=[], @response_code=200>, #<StockQuote::Stock:0x007fc96afd48b0 @symbol="V", @history=[{:date=>"6-Nov-17", :open=>111.36, :high=>112.15, :low=>111.2, :close=>111.92, :volume=>4094744}, {:date=>"3-Nov-17", :open=>110.94, :high=>111.42, :low=>110.5, :close=>111.36, :volume=>3758386}], @response_code=200>]

Any ticker that has . in it, returns two quotes. Can you please fix this issue?
Thank You.

Yahoo Finance is back online

The Yahoo Finance API is back online. Are there any plans to include it in this gem? The IEX one has numerous problems such as constantly banning VPNs, inconsistent update times of previous day's quotes, inability to get prior day's close price after the market as opened, and likely others. The Yahoo one always worked great. If you are not planning to do this yourself, I could probably fork and make a pull req when I have some free time if you are willing to pull it in. Please let me know.

Endpoints that used to work now give "unexpected token" errors

I had automation that used endpoints provided through this gem. One example is a simple:

stock_chart = StockQuote::Stock.raw_chart('AAPL','5y')

This used to return with the stock_chart json object but now it returns this error:

ERROR: 765: unexpected token at 'Forbidden'
C:/Ruby25-x64/lib/ruby/2.5.0/json/common.rb:156:in parse' C:/Ruby25-x64/lib/ruby/2.5.0/json/common.rb:156:in parse'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/stock_quote-2.0.0/lib/stock_quote/stock.rb:68:in block in request' C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rest-client-2.0.2-x64-mingw32/lib/restclient/request.rb:807:in process_result'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rest-client-2.0.2-x64-mingw32/lib/restclient/request.rb:725:in block in transmit' C:/Ruby25-x64/lib/ruby/2.5.0/net/http.rb:910:in start'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rest-client-2.0.2-x64-mingw32/lib/restclient/request.rb:715:in transmit' C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rest-client-2.0.2-x64-mingw32/lib/restclient/request.rb:145:in execute'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rest-client-2.0.2-x64-mingw32/lib/restclient/request.rb:52:in execute' C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/stock_quote-2.0.0/lib/stock_quote/stock.rb:67:in request'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/stock_quote-2.0.0/lib/stock_quote/stock.rb:63:in batch' C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/stock_quote-2.0.0/lib/stock_quote/stock.rb:25:in block (2 levels) in create_method'

IEX Library - Specific date syntax in RoR

Good afternoon,

I've been able to succesfully use the library, using different methods in RoR, like:

StockQuote::Stock.quote
StockQuote::Stock.stats
StockQuote::Stock.chart

But I'm having issues to fetch an specific date. For example, I can fetch the last 6 months in a daily basis, using:

@stock_chart = StockQuote::Stock.chart(params[:id], '6m')

But I need to fetch an specific date with this method. In the iextrading documentation, it says:

"Specific date : IEX-only data by minute for a specified date in the format YYYYMMDD if available. Currently supporting trailing 30 calendar days''

And the HTTP requested is:

/stock/aapl/chart/date/20180620

I tried to execute this commend in Ruby On Rails. But I haven't been able to translate the HTTP request, into RoR format in order to be succesfully fetched the trend data. In the stock_quote documentation there is not also any reference to this specific command.

I appreciate any help with this issue, I've tried around 20+ syntax ways but didn't worked.

Thanks in advance. Regards, Pablo L.

Post Data: Is my first time commenting in Github. Maybe this section is not the proper one to ask this kind of question. If so, I'd appreciate to kindly be refered to the proper site to ask this question. Thanks!

Stack level too deep because of self referencial method 'history'

.history method not working, because it just self references itself
As a result it gives

s = StockQuote::Stock.history('SPY', '2016-11-30', '2016-11-30', 'json')
SystemStackError: stack level too deep
	from (irb):3

Because the method is defined as:

def self.history(symbol, start_date=nil, end_date=nil, format=nil)
  self.history(symbol, start_date, end_date, format)
end

real_time values are not shown

Hi
currentTradingSession = StockQuote::Stock.quote(tickers[n])

I'm testing live currentTradingSession.ask_realtime and other real_time values are returned as NilClass.
Other non real_time values are properly returned as Float but seems like 20 minutes behind compared to actual prices.
Is this a known issue and a limitation of gem/API or am I doing something wrong?
Thank you!

IEX Cloud Has Changed their Pricing Structure

IEX Cloud has moved away from a B2C model and now targets B2B clients. We now price data in bundles (https://iexcloud.io/pricing) which for the most part are out of reach of retail consumers. This is especially so for the stock_quote endpoint used in this code; that now costs $1500/month to access.

If you just need prices, I would suggest refactoring this code to point to the IEX Bid, Ask, and Last Trade Bundle (https://iexcloud.io/documentation/financial-data/data-bundles/market-data/iex-bid-ask-and-last-trade.html) which has prices and quotes that take place on IEX Exchange, and is priced at $20/month. It does not however include extended hours prices, prices and trades from exchanges other than IEX, or other calculated fields included in the more expensive stock_quote endpoint.

Best,
Justin Hunter
Senior Product Manager - IEX Cloud

historical quotes

Hi,

have you tried to get historical quotes recently because this is stalling my system:

stocks = StockQuote::Stock.history('aapl', 1.month.ago, 1.day.ago)

Stock Instances getting Data?

Why does:
StockQuote::Stock.quote('aapl', nil, nil, ['Symbol', 'Ask', 'Bid']).ask
this return the ask for aaple
but
StockQuote::Stock.quote('aapl', nil, nil, ['Symbol', 'Ask', 'AskRealtime']).AskRealtime
this returns an error :
undefined method `AskRealtime' for #StockQuote::Stock:0x0000010126bec8 (NoMethodError)

Can you please document the stock instance usage a little bit more.

PercentChangeFromYearHigh

quote.PercentChangeFromYearHigh
quote.percent_change_from_year_high
(and the misspellings in the source feed)

return nil, even though quote.inspect shows both the field and the value.

All other fields return fine.

API Key

How can I get an API key? I'm trying to use this gem on my current project, the link to sign up for the API key wasn't going through.

quote throws JSON::ParserError for certain symbols

It seems like StockQuote::Stock.quote can't parse the JSON from a number of the response it's getting back. I tried this on Linux and then again on a Mac, a couple different Ruby versions too. Currently on 2.1.4, but tried latest stable as well.

For examples of symbols that seem to provoke this issue, please see:

require 'stock_quote' 

examples = [
  'AON', 'JCI', 'PH', 'A', 'MYL', 'INFO', 'SNPS', 'ALLY', 'MSCI',
  'FANG', 'XL', 'FOX', 'BR', 'BG', 'NI', 'ST', 'Y', 'KEYS',
  'AYI', 'MIDD', 'BLUE', 'SCI', 'SERV', 'COMM', 'SNAP', 'RS',
  'SON', 'TECH', 'Z'
]

examples.each do |symbol|
  begin
    quote = StockQuote::Stock.quote symbol 
  rescue JSON::ParserError => msg 
    puts "Either Google's API is dispensing invalid JSON for #{symbol} or..."
    puts "Something is wrong with stock_quote..."
    puts msg 
    next  
  end

  puts "Or maybe something is wrong with me."
end 

Can't quite figure out what exactly it's objecting to in the response, the output is rather large but also incomplete.

JSON::ParserError: 757: unexpected token at 'tart" : "","num" : "","num_company_results" : "571","num_mf_results" : "1066","num_all_results" : "","original_query" : "Z","query_for_display" : "Z","results_type" : "DEFAULT","searchresults" :[{"title" : "La-Z-Boy Incorporated","id" : "21057","is_active" : "","ticker" : "LZB","exchange" : "NYSE","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Royal Bank of Canada","id" : "427488555729150","is_active" : "","ticker" : "RY-Z","exchange" : "TSE","is_supported_exchange" : "","local_currency_symbol" : "CA$","columns" : []}, {"title" : "CA, Inc.","id" : "8500","is_active" : "","ticker" : "CA","exchange" : "NASDAQ","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Bank of America Corporation BAC Capital Trust VIII 6% Capital Securities","id" : "5096791","is_active" : "","ticker" : "BAC-Z.CL","exchange" : "NYSE","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "J P Morgan Chase \u0026 Co Cap Secs Var Ser Z 12\u002F31\u002F2048","id" : "10634449","is_active" : "","ticker" : "JPM-Z.CL","exchange" : "NYSE","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "HSBC USA, Inc. CL \u0027CL\u0027 PRFD \u0027Z.CL\u0027","id" : "9958998","is_active" : "","ticker" : "HUSI-Z.CL","exchange" : "NYSE","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Regions Fing Tr III Tr Pfd Secs 06\u002F15\u002F2078","id" : "11523241","is_active" : "","ticker" : "RF-Z","exchange" : "NYSE","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Z-Obee Holdings Ltd","id" : "14893800","is_active" : "","ticker" : "0948","exchange" : "HKG","is_supported_exchange" : "","local_currency_symbol" : "HK$","columns" : []}, {"title" : "SunTrust Banks, Inc. Suntrust Capital IX 7.875% Trust Preferred Securities","id" : "5007980","is_active" : "","ticker" : "STI-Z","exchange" : "NYSE","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Apartment Investment and Management Co","id" : "5313417","is_active" : "","ticker" : "AIV-Z.CL","exchange" : "NYSE","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Zinc One Resources Inc","id" : "716140","is_active" : "","ticker" : "Z","exchange" : "CVE","is_supported_exchange" : "","local_currency_symbol" : "CA$","columns" : []}, {"title" : "Autoliv, Inc. Corp Unit","id" : "8101780","is_active" : "","ticker" : "ALV-Z","exchange" : "NYSE","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Johnson Controls, Inc. Corp Unit","id" : "8700113","is_active" : "","ticker" : "JCI-Z.CL","exchange" : "NYSE","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Public Storage Publlic Storage, Inc. Depositary Share Series Z","id" : "13899203","is_active" : "","ticker" : "","exchange" : "","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Ci:z Holdings Co Ltd","id" : "685229","is_active" : "","ticker" : "4924","exchange" : "TYO","is_supported_exchange" : "","local_currency_symbol" : "¥","columns" : []}, {"title" : "Z Gallerie, LLC","id" : "3616665","is_active" : "","ticker" : "","exchange" : "","is_supported_exchange" : "","local_currency_symbol" : "-","columns" : []}, {"title" : "Z Corporation","id" : "2554659","is_active" : "","ticker" : "","exchange" : "","is_supported_exchange" : "","local_currency_symbol" : "-","columns" : []}, {"title" : "Z Energy Ltd","id" : "439717741744784","is_active" : "","ticker" : "ZEL","exchange" : "NZE","is_supported_exchange" : "","local_currency_symbol" : "NZ$","columns" : []}, {"title" : "Capital Z Management, LLC","id" : "3906016","is_active" : "","ticker" : "","exchange" : "","is_supported_exchange" : "","local_currency_symbol" : "-","columns" : []}, {"title" : "AviChina Industry \u0026 Technology Co Ltd","id" : "688860","is_active" : "","ticker" : "2357","exchange" : "HKG","is_supported_exchange" : "","local_currency_symbol" : "HK$","columns" : []}],"mf_searchresults" :[{"title" : "Columbia Value and Restructuring Fund Class Z","id" : "43941755427292","is_active" : "","ticker" : "UMBIX","exchange" : "MUTF","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Touchstone Sands Capital Select Growth Fund Class Z","id" : "7759470454357","is_active" : "","ticker" : "PTSGX","exchange" : "MUTF","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Prudential Jennison Growth Fund Class Z","id" : "769291539680209","is_active" : "","ticker" : "PJFZX","exchange" : "MUTF","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Franklin Mutual Global Discovery Fund Class Z","id" : "218019676354140","is_active" : "","ticker" : "MDISX","exchange" : "MUTF","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Columbia Large Cap Growth Fund II Class Z","id" : "613166786496134","is_active" : "","ticker" : "NMYAX","exchange" : "MUTF","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "AMG TimesSquare Mid Cap Growth Fund Class Z","id" : "379819052250780","is_active" : "","ticker" : "TMDIX","exchange" : "MUTF","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Franklin Mutual Shares Fund Class Z","id" : "932077600196270","is_active" : "","ticker" : "MUTHX","exchange" : "MUTF","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Franklin Mutual Quest Fund Class Z","id" : "271587861591046","is_active" : "","ticker" : "MQIFX","exchange" : "MUTF","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Prudential Jennison Natural Resources Fund Class Z","id" : "33348043363522","is_active" : "","ticker" : "PNRZX","exchange" : "MUTF","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Prudential Jennison Mid-Cap Growth Fund, Inc Class Z","id" : "28046060491903","is_active" : "","ticker" : "PEGZX","exchange" : "MUTF","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Franklin Mutual Beacon Fund Class Z","id" : "235663387518811","is_active" : "","ticker" : "BEGRX","exchange" : "MUTF","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Target International Equity Portfolio Fund Class Z","id" : "1073966859120379","is_active" : "","ticker" : "TAIEX","exchange" : "MUTF","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Prudential Jennison Small Company Fund Class Z","id" : "828277264034160","is_active" : "","ticker" : "PSCZX","exchange" : "MUTF","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Prudential Jennison Health Sciences Fund Class Z","id" : "266075624098149","is_active" : "","ticker" : "PHSZX","exchange" : "MUTF","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Franklin Mutual European Fund Class Z","id" : "465001737452351","is_active" : "","ticker" : "MEURX","exchange" : "MUTF","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Prudential Short-Term Corporate Bond Fund Class Z","id" : "651889985205405","is_active" : "","ticker" : "PIFZX","exchange" : "MUTF","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Prudential High-Yield Fund Class Z","id" : "490452772294254","is_active" : "","ticker" : "PHYZX","exchange" : "MUTF","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Prudential Corporate Bond Fund Class Z","id" : "926627073221877","is_active" : "","ticker" : "TGMBX","exchange" : "MUTF","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Prudential Total Return Bond Fund Class Z","id" : "475285720482124","is_active" : "","ticker" : "PDBZX","exchange" : "MUTF","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}, {"title" : "Columbia Large Cap Growth Fund V Class Z","id" : "994437973422510","is_active" : "","ticker" : "NGIPX","exchange" : "MUTF","is_supported_exchange" : "","local_currency_symbol" : "$","columns" : []}]}'

All of them seem to start: 'tart" : "",.

ArgumentError: invalid date

Current running this gem version

stock_quote (1.2.5)

Ruby version

ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin14]

When I get the result of certain stocks it's throwing an invalid date error as seen below. Seems to be a bug in the gem not handling the date attributes properly?

ArgumentError: invalid date
/var/www/app_path/vendor/bundle/ruby/2.3.0/gems/stock_quote-1.2.5/lib/stock_quote/utility.rb:42:in `strptime'
/var/www/app_path/vendor/bundle/ruby/2.3.0/gems/stock_quote-1.2.5/lib/stock_quote/utility.rb:42:in `to_date'
/var/www/app_path/vendor/bundle/ruby/2.3.0/gems/stock_quote-1.2.5/lib/stock_quote/utility.rb:12:in `to_format'
/var/www/app_path/vendor/bundle/ruby/2.3.0/gems/stock_quote-1.2.5/lib/stock_quote/stock.rb:60:in `block in initialize'
/var/www/app_path/vendor/bundle/ruby/2.3.0/gems/stock_quote-1.2.5/lib/stock_quote/stock.rb:59:in `each'
/var/www/app_path/vendor/bundle/ruby/2.3.0/gems/stock_quote-1.2.5/lib/stock_quote/stock.rb:59:in `map'
/var/www/app_path/vendor/bundle/ruby/2.3.0/gems/stock_quote-1.2.5/lib/stock_quote/stock.rb:59:in `initialize'
/var/www/app_path/vendor/bundle/ruby/2.3.0/gems/stock_quote-1.2.5/lib/stock_quote/stock.rb:141:in `new'
/var/www/app_path/vendor/bundle/ruby/2.3.0/gems/stock_quote-1.2.5/lib/stock_quote/stock.rb:141:in `block in parse'
/var/www/app_path/vendor/bundle/ruby/2.3.0/gems/stock_quote-1.2.5/lib/stock_quote/stock.rb:139:in `each'
/var/www/app_path/vendor/bundle/ruby/2.3.0/gems/stock_quote-1.2.5/lib/stock_quote/stock.rb:139:in `parse'
/var/www/app_path/vendor/bundle/ruby/2.3.0/gems/stock_quote-1.2.5/lib/stock_quote/stock.rb:86:in `block in quote'
/var/www/app_path/vendor/bundle/ruby/2.3.0/gems/rest-client-1.8.0/lib/restclient/request.rb:493:in `process_result'
/var/www/app_path/vendor/bundle/ruby/2.3.0/gems/rest-client-1.8.0/lib/restclient/request.rb:421:in `block in transmit'
/var/www/app_path/vendor/bundle/ruby/2.3.0/gems/rest-client-1.8.0/lib/restclient/request.rb:413:in `transmit'
/var/www/app_path/vendor/bundle/ruby/2.3.0/gems/rest-client-1.8.0/lib/restclient/request.rb:176:in `execute'
/var/www/app_path/vendor/bundle/ruby/2.3.0/gems/rest-client-1.8.0/lib/restclient/request.rb:41:in `execute'
/var/www/app_path/vendor/bundle/ruby/2.3.0/gems/stock_quote-1.2.5/lib/stock_quote/stock.rb:84:in `quote'

Need human readable attribute names

Since updating to the Google Finance API, we now need a dictionary of attributes to human readable names. Here are the attributes provided by Google:

symbol, exchange, id, t, e, name, f_reuters_url, f_recent_quarter_date, f_annlyal_date, f_ttm_date, financials, kr_recent_quarter_date, kr_annual_date, kr_ttm_date, c, l, cp, ccol, op, hi, lo, vo, avvo, hi52, lo52, mc, pe, fwpe, beta, eps, dy, ldiv, shares, instown, eo, sid, sname, iid, iname, related, summary, management, moreresources, events

error right after install

Hello, this error shows for these methods right after i installed the gem.

2.4.1 :004 > StockQuote::Stock.quote("GOOG").open
NoMethodError: private method `open' called for #<StockQuote::Stock:0x007f8c04198ee8>
	from (irb):4
2.4.1 :005 > StockQuote::Stock.quote('goog').open
NoMethodError: private method `open' called for #<StockQuote::Stock:0x007f8c04167500>
	from (irb):5

Rails errors after upgrade to 1.1.4

After upgrading my app to use version 1.1.4 of this gem, I got "Uninitialized Constant" errors for all of my controllers. Downgrading the gem made everything work again.

I figured it had to do with some kind of parsing issue, and it appears that in the utility.rb code, the 'underscore' method is missing periods at the end of each line of the method. Version 1.1.2 has the periods, 1.1.4 doesn't. I's not entirely clear to me why that would cause such catastrophic failure in my app, but adding them back in makes 1.1.4 work for me.

I'm using Rails 4 / Ruby 2.1.1

Yahoo API OEL - Versions < 1.5.0 will not function.

On November 1st, 2017, Yahoo Finance terminated public access to the API and stock_quote ceased to function in it's current state. Therefore, Version 1.5.0 now utilizes the Google Finance API and although functionally similar, the results, and therefore attributes, have changed. Please update accordingly.

Unfortunately, every version below 1.5.0 is broken due to the change. Sorry for the inconvenience.

400 Bad Request

Hello,

FYI, we get a 400 Bad Request about 50% of the time when calling the array version of the call from the documentation: stocks = StockQuote::Stock.quote(["aapl", "tsla"])

history not working

I freshly installed Version 1.5.4
These two commands yield the same results in irb:

require 'stock_quote'
StockQuote::Stock.history("inl.de")
require 'stock_quote'
StockQuote::Stock.quote("inl.de")

And for this I am just getting a runtime Error:
StockQuote::Stock.history("inl.de", "2017-01-01", "2017-12-01")
RuntimeError: Invalid Query

Any ideas how to fix this?

Typo in attributes

percent_change_from_year_high actually returns percebt_change_from_year_high

Invalid symbols

The #json_quote method returns quotes with valid symbols.

irb(main):016:0> StockQuote::Stock.json_quote('AAPL, MSFT, GOOG', nil, nil, ['Symbol', 'LastTradePriceOnly'])
=> {"quote"=>[{"LastTradePriceOnly"=>"105.68", "Symbol"=>"AAPL"}, {"LastTradePriceOnly"=>"51.78", "Symbol"=>"MSFT"}, {"LastTradePriceOnly"=>"718.77", "Symbol"=>"GOOG"}]}

But the #quote method returns quotes without valid symbols.

irb(main):017:0> StockQuote::Stock.quote('AAPL, MSFT, GOOG', nil, nil, ['Symbol', 'LastTradePriceOnly'])
=> [#<StockQuote::Stock:0x007fff431e8440 @response_code=200, @symbol="'AAPL','MSFT','GOOG'", @last_trade_price_only=105.68>, #<StockQuote::Stock:0x007fff431e80a8 @response_code=200, @symbol="'AAPL','MSFT','GOOG'", @last_trade_price_only=51.78>, #<StockQuote::Stock:0x007fff431f2648 @response_code=200, @symbol="'AAPL','MSFT','GOOG'", @last_trade_price_only=718.77>]

Rails 5 Cipher Not Found

Since upgrading to Rails 5 ( using Ruby 2.4.1 ), I am getting the following error when trying to receive a stock price via stock_quote:
key not found: :ciphers

Here is the console output:

Loading development environment (Rails 5.0.2)
2.4.1 :001 >     @stock = StockQuote::Stock.quote("aapl")
KeyError: key not found: :ciphers

Historical Data Deprecated by Yahoo

It seems historical data isn't supported by Yahoo anymore(at least not through the yahooapis YQL mechanism) or am I using it wrong? If it is deprecated we should update the README that references the capabilities(in particular the section on Date Range).

irb(main):021:0> StockQuote::Stock.quote("aapl", "2017-07-16", "2017-07-22")
StockQuote::NoDataForStockError: StockQuote::NoDataForStockError
irb(main):022:0> StockQuote::Stock.history("aapl", "2017-07-16", "2017-07-22")
StockQuote::ApiChange: Yahoo discontinued the historical quote API on May 17th, 2017.

App crashes if IEX returns 404

Currently trying to prevent junky user input on a search form. If I search for a symbol that doesn't exist, IEX returns a 404 and my app crashes showing a 404 response ("Unknown symbol").

Using Ruby 3.1.2 and Rails 7.0.2. Please let me know what other information I can provide.

Screen Shot 2022-05-01 at 4 15 35 PM

OpenSSL::SSL::SSLError

Its working now. I didnt know how to delete this issue.

#executed from console
stock = StockQuote::Stock.quote("AAPL")

#received Error:
OpenSSL::SSL::SSLError: SSL_connect SYSCALL returned=5 errno=0 state=SSLv2/v3 read server hello A

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.