Class: YahooFinance::Client
- Inherits:
-
Object
- Object
- YahooFinance::Client
- Includes:
- FinanceUtils
- Defined in:
- lib/yahoo-finance.rb
Overview
Client for Yahoo Finance Queries
Constant Summary collapse
- COLUMNS =
{ ask: "a", average_daily_volume: "a2", ask_size: "a5", bid: "b", ask_real_time: "b2", bid_real_time: "b3", book_value: "b4", bid_size: "b6", change_and_percent_change: "c", change: "c1", comission: "c3", change_real_time: "c6", after_hours_change_real_time: "c8", dividend_per_share: "d", last_trade_date: "d1", trade_date: "d2", earnings_per_share: "e", error_indicator: "e1", eps_estimate_current_year: "e7", eps_estimate_next_year: "e8", eps_estimate_next_quarter: "e9", float_shares: "f6", low: "g", high: "h", low_52_weeks: "j", high_52_weeks: "k", holdings_gain_percent: "g1", annualized_gain: "g3", holdings_gain: "g4", holdings_gain_percent_realtime: "g5", holdings_gain_realtime: "g6", more_info: "i", order_book: "i5", market_capitalization: "j1", shares_outstanding: "j2", market_cap_realtime: "j3", ebitda: "j4", change_From_52_week_low: "j5", percent_change_from_52_week_low: "j6", last_trade_realtime_withtime: "k1", change_percent_realtime: "k2", last_trade_size: "k3", change_from_52_week_high: "k4", percent_change_from_52_week_high: "k5", last_trade_with_time: "l", last_trade_price: "l1", close: "l1", high_limit: "l2", low_limit: "l3", days_range: "m", days_range_realtime: "m2", moving_average_50_day: "m3", moving_average_200_day: "m4", change_from_200_day_moving_average: "m5", percent_change_from_200_day_moving_average: "m6", change_from_50_day_moving_average: "m7", percent_change_from_50_day_moving_average: "m8", name: "n", notes: "n4", open: "o", previous_close: "p", price_paid: "p1", change_in_percent: "p2", price_per_sales: "p5", price_per_book: "p6", ex_dividend_date: "q", pe_ratio: "r", dividend_pay_date: "r1", pe_ratio_realtime: "r2", peg_ratio: "r5", price_eps_estimate_current_year: "r6", price_eps_Estimate_next_year: "r7", symbol: "s", shares_owned: "s1", revenue: "s6", short_ratio: "s7", last_trade_time: "t1", trade_links: "t6", ticker_trend: "t7", one_year_target_price: "t8", volume: "v", holdings_value: "v1", holdings_value_realtime: "v7", weeks_range_52: "w", day_value_change: "w1", day_value_change_realtime: "w4", stock_exchange: "x", dividend_yield: "y", adjusted_close: nil # only in historical quotes ^ }
- HISTORICAL_MODES =
{ daily: "d", weekly: "w", monthly: "m", dividends_only: "v" }
- SYMBOLS_PER_REQUEST =
50
Constants included from FinanceUtils
Instance Method Summary collapse
- #historical_quotes(symbol, options = {}) ⇒ Object
- #quote(symbol, columns_array = [ :symbol, :last_trade_price, :last_trade_date, :change, :previous_close], options = {}) ⇒ Object
-
#quotes(symbols_array, columns_array = [ :symbol, :last_trade_price, :last_trade_date, :change, :previous_close], options = {}) ⇒ Object
retrieve the quote data (an OpenStruct per quote) the options param can be used to specify the following attributes: :raw - if true, each column will be converted (to numbers, dates, etc).
- #splits(symbol, options = {}) ⇒ Object
- #symbols(query) ⇒ Object
Methods included from FinanceUtils
Instance Method Details
#historical_quotes(symbol, options = {}) ⇒ Object
139 140 141 142 143 144 145 |
# File 'lib/yahoo-finance.rb', line 139 def historical_quotes(symbol, = {}) [:raw] ||= true [:period] ||= :daily read_historical(symbol, ).map do |row| OpenStruct.new(row.to_hash.merge(symbol: symbol)) end end |
#quote(symbol, columns_array = [ :symbol, :last_trade_price, :last_trade_date, :change, :previous_close], options = {}) ⇒ Object
131 132 133 134 135 136 137 |
# File 'lib/yahoo-finance.rb', line 131 def quote(symbol, columns_array = [ :symbol, :last_trade_price, :last_trade_date, :change, :previous_close], = {}) [:raw] ||= true quotes([symbol], columns_array, ).first end |
#quotes(symbols_array, columns_array = [ :symbol, :last_trade_price, :last_trade_date, :change, :previous_close], options = {}) ⇒ Object
retrieve the quote data (an OpenStruct per quote) the options param can be used to specify the following attributes: :raw - if true, each column will be converted (to numbers, dates, etc)
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/yahoo-finance.rb', line 114 def quotes(symbols_array, columns_array = [ :symbol, :last_trade_price, :last_trade_date, :change, :previous_close], = {}) [:raw] ||= true ret = [] symbols_array.each_slice(SYMBOLS_PER_REQUEST) do |symbols| read_quotes(symbols.join("+"), columns_array).map do |row| if [:na_as_nil] row.each{ |key, value| row[key] = nil if value == 'N/A' } end ret << OpenStruct.new(row.to_hash) end end ret end |
#splits(symbol, options = {}) ⇒ Object
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/yahoo-finance.rb', line 155 def splits(symbol, = {}) rows = read_splits(symbol, ).select { |row| row[0] == "SPLIT" } rows.map do |row| type, date, value = row after, before = value.split(":") OpenStruct.new( symbol: symbol, date: Date.strptime(date.strip, "%Y%m%d"), before: before.to_i, after: after.to_i) end end |
#symbols(query) ⇒ Object
147 148 149 150 151 152 153 |
# File 'lib/yahoo-finance.rb', line 147 def symbols(query) ret = [] read_symbols(query).each do |row| ret << OpenStruct.new(row) end ret end |