Stock.rb

Grabs information about a stock from Yahoo! Finance.

Installation

  • Via RubyGems gem install stock

Basic Usage

You can grab the entire information of a stock like so:

require 'stock'

facebook = Stock.new('fb')
puts facebook.d

OUTPUT

{
   "sourceInterval":15,
   "regularMarketOpen":{
      "raw":181.78,
      "fmt":"181.78"
   },
   "exchange":"NMS",
   "regularMarketTime":{
      "raw":1520370002,
      "fmt":"4:00PM EST"
   },
   "sharesOutstanding":{
      "raw":2395919872,
      "fmt":"2.396B",
      "longFmt":"2,395,919,872"
   },
   "regularMarketDayHigh":{
      "raw":182.38,
      "fmt":"182.38"
   },
   "shortName":"Facebook, Inc.",
   "longName":"Facebook, Inc.",
   "exchangeTimezoneName":"America/New_York",
   "regularMarketChange":{
      "raw":-0.6199951,
      "fmt":"-0.62"
   },
   "regularMarketPreviousClose":{
      "raw":180.4,
      "fmt":"180.40"
   },
   "fiftyTwoWeekHighChange":{
      "raw":-15.540009,
      "fmt":"-15.54"
   },
   "exchangeTimezoneShortName":"EST",
   "fiftyTwoWeekLowChange":{
      "raw":42.789993,
      "fmt":"42.79"
   },
   "exchangeDataDelayedBy":0,
   "regularMarketDayLow":{
      "raw":179.11,
      "fmt":"179.11"
   },
   "priceHint":2,
   "currency":"USD",
   "regularMarketPrice":{
      "raw":179.78,
      "fmt":"179.78"
   },
   "regularMarketVolume":{
      "raw":15086784,
      "fmt":"15.087M",
      "longFmt":"15,086,784"
   },
   "isLoading":false,
   "gmtOffSetMilliseconds":-18000000,
   "marketState":"POSTPOST",
   "marketCap":{
      "raw":522260873216,
      "fmt":"522.261B",
      "longFmt":"522,260,873,216"
   },
   "quoteType":"EQUITY",
   "invalid":false,
   "symbol":"FB",
   "language":"en-US",
   "fiftyTwoWeekLowChangePercent":{
      "raw":0.3123585,
      "fmt":"31.24%"
   },
   "messageBoardId":"finmb_20765463",
   "fiftyTwoWeekHigh":{
      "raw":195.32,
      "fmt":"195.32"
   },
   "fiftyTwoWeekHighChangePercent":{
      "raw":-0.079561785,
      "fmt":"-7.96%"
   },
   "uuid":"30781f1f-c2f9-342c-ab1a-d2f6f35a51db",
   "market":"us_market",
   "fiftyTwoWeekLow":{
      "raw":136.99,
      "fmt":"136.99"
   },
   "regularMarketChangePercent":{
      "raw":-0.343678,
      "fmt":"-0.34%"
   },
   "fullExchangeName":"NasdaqGS",
   "tradeable":true
}

You can also grab singular pieces of information about a stock like so:

require 'stock'

facebook = Stock.new('fb')
p facebook.d['shortName'] #=> 'Facebook, Inc.'

License

Copyright © 2018 Marcello Sabino ([email protected]) and released under the MIT License.