Class: PBYF

Inherits:
Object
  • Object
show all
Defined in:
lib/pbyf.rb

Constant Summary collapse

@@quote_url =

these are the base urls for querying various parts of yahoo finance

'http://download.finance.yahoo.com/d/quotes.csv?s='
@@historical_quote_url =
'http://ichart.yahoo.com/table.csv?s='

Class Method Summary collapse

Class Method Details

.get_hist_quote(str_of_stock, from_date, to_date, interval = 'd') ⇒ Object

one cannot get multiple stocks for historical quotes, you must get them separately for now dates will be assumed to be the format Month-Day-Year, i.e. 3-19-1988 this should return an array of arrays of [Date, Open, High, Low, Close, Volume, Adj Close]



21
22
23
24
25
26
27
# File 'lib/pbyf.rb', line 21

def self.get_hist_quote str_of_stock, from_date, to_date, interval = 'd'
  from = from_date.split('-')
  to = to_date.split('-')
  from_to_params = "&a=#{from[0].to_i-1}" + "&b=#{from[1]}" + "&c=#{from[2]}" + "&d=#{to[0].to_i-1}" + "&e=#{to[1]}" + "&f=#{to[2]}"
  query_url = @@historical_quote_url + str_of_stock + from_to_params + "&g=#{interval}"
  arr_of_arrays = CSV.parse(RestClient.get query_url)
end

.get_quote(str_of_stocks, str_of_options) ⇒ Object

str_of_stocks should be formatted according to yahoo finance api docs might need to do work here on the formatting when multiple stocks are requested



13
14
15
16
# File 'lib/pbyf.rb', line 13

def self.get_quote str_of_stocks, str_of_options
  query_url = @@quote_url + str_of_stocks + '&f=' + str_of_options
  arr_of_arrays = CSV.parse(RestClient.get query_url)
end