yahoo-finance 0.0.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c6a015a18c3319e26d41dbacde9bf2d76c5db9bf
4
+ data.tar.gz: 9cde1310a1f8aa6585f1907a5300b732a3177410
5
+ SHA512:
6
+ metadata.gz: 451ea63a655451a65a446c4d8596b32907140d9b01fbfd83353fbf1c401bc334e521eaa873caff4defdaae6348ecac853c959796efb4ff6270d0e4a8548fa4ce
7
+ data.tar.gz: 95647240723348756960cab2ecd423b9df7f98f50b5414fba507a17b1c7bb876bf1c77c0f17943abdd927f6d66221167dd3f8c87eb136f55586fe09bbfca4c65
data/HISTORY CHANGED
@@ -1,8 +1,19 @@
1
- Version 0.0.2 - August 05, 2007
1
+ 0.2.0 - Nov 24, 2014
2
+ ====================
3
+ * Allow fetching a single symbol with the `quote` method
4
+ * Multiple fixes to comply w/ Yahoo API changes
5
+ * Optional start/end dates (the quotes method now takes an options hash)
6
+
7
+ 0.1.0 - Apr 05, 2011
8
+ ===============================
9
+ * Use ruby CSV
10
+ * Refactor
11
+
12
+ 0.0.2 - Aug 05, 2007
2
13
  ===============================
3
14
  * Type-casting: pass the option :raw => false to the quotes method to get columns converted from string to specific types (mostly float, date, time and datetime)
4
15
  * Historical quotes: a convenient method to get historical quotes for a given symbol in an interval, getting either daily, weekly or monthly quotes - or dividend yields only
5
16
 
6
- Version 0.0.1 - August 04, 2007
17
+ 0.0.1 - Aug 04, 2007
7
18
  ===============================
8
- * Initial implementation - no bells, no whristles :)
19
+ * Initial implementation - no bells, no whristles :)
@@ -1,131 +1,162 @@
1
- Ruby's Yahoo Finance Wrapper
2
- ============================
3
-
1
+ # Ruby's Yahoo Finance Wrapper
4
2
  A dead simple wrapper for yahoo finance quotes end-point.
5
3
 
6
- Usage:
4
+ ## Installation:
5
+
6
+ `gem install 'yahoo-finance'`
7
+ `require 'yahoo_finance'`
8
+
9
+ If using bundler:
10
+ `gem 'yahoo-finance', require: 'yahoo_finance'`
11
+
12
+ ## Usage:
7
13
 
8
- 1 - Getting latest quotes for a set of symbols
9
- ----------------------------------------------
10
- Just pass an array of symbols (stock names, indexes, exchange rates) and a list of fields you want:
14
+ ### Getting latest quotes for a set of symbols
11
15
 
16
+ Pass an array of valid symbols (stock names, indexes, exchange rates) and a list of fields you want:
17
+
18
+ ```ruby
12
19
  data = YahooFinance.quotes(["BVSP", "NATU3.SA", "USDJPY=X"], [:ask, :bid, :last_trade_date])
13
- # ask will be a string here:
14
- puts data[0].symbol + " value is: " + data[0].ask
20
+ ```
15
21
 
16
- Or optionally:
22
+ Data is now an array of results. You now have accessor methods to retrieve the data, with the return results being strings:
17
23
 
18
- data = YahooFinance.quotes(["BVSP", "NATU3.SA", "USDJPY=X"], [:ask, :bid, :last_trade_date], { :raw => false } )
19
- # ask will be a float here:
24
+ ```ruby
20
25
  puts data[0].symbol + " value is: " + data[0].ask
26
+ ```
27
+
28
+ Passing `raw: false` will return numerical values
29
+
30
+ ```ruby
31
+ data = YahooFinance.quotes(["BVSP", "NATU3.SA", "USDJPY=X"], [:ask, :bid, :last_trade_date], { raw: false } )
32
+ data[0].ask # This is now a float
33
+ ```
21
34
 
22
35
  The full list of fields follows:
23
36
 
37
+ ``` ruby
38
+ :after_hours_change_real_time
39
+ :annualized_gain
24
40
  :ask
25
- :average_daily_volume
41
+ :ask_real_time
26
42
  :ask_size
43
+ :average_daily_volume
27
44
  :bid
28
- :ask_real_time
29
45
  :bid_real_time
30
- :book_value b4
31
- :bid_size b6
32
- :chance_and_percent_change
46
+ :bid_size
47
+ :book_value
33
48
  :change
34
- :comission
49
+ :change_and_percent_change
50
+ :change_from_200_day_moving_average
51
+ :change_from_50_day_moving_average
52
+ :change_from_52_week_high
53
+ :change_From_52_week_low
54
+ :change_in_percent
55
+ :change_percent_realtime
35
56
  :change_real_time
36
- :after_hours_change_real_time
57
+ :close
58
+ :comission
59
+ :day_value_change
60
+ :day_value_change_realtime
61
+ :days_range
62
+ :days_range_realtime
63
+ :dividend_pay_date
37
64
  :dividend_per_share
38
- :last_trade_date
39
- :trade_date
65
+ :dividend_yield
40
66
  :earnings_per_share
41
- :error_indicator
67
+ :ebitda
42
68
  :eps_estimate_current_year
43
- :eps_estimate_next_year
44
69
  :eps_estimate_next_quarter
70
+ :eps_estimate_next_year
71
+ :error_indicator
72
+ :ex_dividend_date
45
73
  :float_shares
46
- :low
47
74
  :high
48
- :low_52_weeks
49
75
  :high_52_weeks
50
- :holdings_gain_percent
51
- :annualized_gain
76
+ :high_limit
52
77
  :holdings_gain
78
+ :holdings_gain_percent
53
79
  :holdings_gain_percent_realtime
54
80
  :holdings_gain_realtime
55
- :more_info
56
- :order_book
57
- :market_capitalization
58
- :market_cap_realtime
59
- :ebitda
60
- :change_From_52_week_low
61
- :percent_change_from_52_week_low
81
+ :holdings_value
82
+ :holdings_value_realtime
83
+ :last_trade_date
84
+ :last_trade_price
62
85
  :last_trade_realtime_withtime
63
- :change_percent_realtime
64
86
  :last_trade_size
65
- :change_from_52_week_high
66
- :percent_change_from_52_week_high
87
+ :last_trade_time
67
88
  :last_trade_with_time
68
- :last_trade_price
69
- :close
70
- :high_limit
89
+ :low
90
+ :low_52_weeks
71
91
  :low_limit
72
- :days_range
73
- :days_range_realtime
74
- :moving_average_50_day
92
+ :market_cap_realtime
93
+ :market_capitalization
94
+ :more_info
75
95
  :moving_average_200_day
76
- :change_from_200_day_moving_average
77
- :percent_change_from_200_day_moving_average
78
- :change_from_50_day_moving_average
79
- :percent_change_from_50_day_moving_average
96
+ :moving_average_50_day
80
97
  :name
81
98
  :notes
99
+ :one_year_target_price
82
100
  :open
83
- :previous_close
84
- :price_paid
85
- :change_in_percent
86
- :price_per_sales
87
- :price_per_book
88
- :ex_dividend_date
101
+ :order_book
89
102
  :pe_ratio
90
- :dividend_pay_date
91
103
  :pe_ratio_realtime
92
104
  :peg_ratio
105
+ :percent_change_from_200_day_moving_average
106
+ :percent_change_from_50_day_moving_average
107
+ :percent_change_from_52_week_high
108
+ :percent_change_from_52_week_low
109
+ :previous_close
93
110
  :price_eps_estimate_current_year
94
111
  :price_eps_Estimate_next_year
95
- :symbol
112
+ :price_paid
113
+ :price_per_book
114
+ :price_per_sales
96
115
  :shares_owned
97
116
  :short_ratio
98
- :last_trade_time
99
- :trade_links
117
+ :stock_exchange
118
+ :symbol
100
119
  :ticker_trend
101
- :one_year_target_price
120
+ :trade_date
121
+ :trade_links
102
122
  :volume
103
- :holdings_value
104
- :holdings_value_realtime
105
123
  :weeks_range_52
106
- :day_value_change
107
- :day_value_change_realtime
108
- :stock_exchange
109
- :dividend_yield
110
-
124
+ ```
111
125
 
112
- 2 - Getting historical quotes
113
- -----------------------------
126
+ ### Getting historical quotes
114
127
 
115
128
  Here you can specify a date range and a symbol, and retrieve historical data for it.
116
129
  The last parameter (options) can include, besides the "raw" option, a "period" option.
117
130
  The period can be specified as :daily, :monthly, :weekly or :dividends_only
118
131
 
119
- data = YahooFinance.historical_quotes("BVSP", Time::now-(24*60*60*10), Time::now) # 10 days worth of data
132
+ ```ruby
133
+ data = YahooFinance.historical_quotes("AAPL") # entire historical data
134
+ ```
135
+
136
+ or
137
+
138
+ ```ruby
139
+ data = YahooFinance.historical_quotes("AAPL", { start_date: Time::now-(24*60*60*10), end_date: Time::now }) # 10 days worth of data
140
+ ```
120
141
 
121
142
  or
122
143
 
123
- data = YahooFinance.historical_quotes("BVSP", Time::now-(24*60*60*10), Time::now, { :raw => false, :period => :monthly })
144
+ ``` ruby
145
+ data = YahooFinance.historical_quotes("AAPL", { raw: false, period: :monthly })
146
+ ```
124
147
 
148
+ ### Getting splits
125
149
 
150
+ You can also retrieve split data.
126
151
 
152
+ ```ruby
153
+ data = YahooFinance.splits('AAPL', :start_date => Date.today - 10*365)
154
+ data[0].date # Date<2014-06-09>
155
+ data[0].before # 1
156
+ data[0].after # 7
157
+ ```
127
158
 
128
159
 
129
160
  Enjoy! :-)
130
161
 
131
- - Herval (contact@hervalicio.us)
162
+ - Herval (hervalfreire@gmail.com)
@@ -0,0 +1 @@
1
+ require 'yahoo_finance'
@@ -1,100 +1,112 @@
1
1
  require 'open-uri'
2
2
  require 'ostruct'
3
+ require 'json'
4
+
5
+ if RUBY_VERSION >= "1.9"
6
+ require 'csv'
7
+ else
8
+ require 'rubygems'
9
+ require 'fastercsv'
10
+ class Object
11
+ CSV = FCSV
12
+ alias_method :CSV, :FCSV
13
+ end
14
+ end
3
15
 
4
16
  class YahooFinance
5
-
6
- VERSION = '0.0.2'
17
+
18
+ VERSION = '0.2.0'
7
19
 
8
20
  COLUMNS = {
9
- :ask => ["a", :float],
10
- :average_daily_volume => ["a2", :float],
11
- :ask_size => ["a5", :integer],
12
- :bid => ["b", :float],
13
- :ask_real_time => ["b2", :time],
14
- :bid_real_time => ["b3", :float],
15
- :book_value => ["b4", :float],
16
- :bid_size => ["b6", :integer],
17
- :chance_and_percent_change => ["c", :string],
18
- :change => ["c1", :float],
19
- :comission => ["c3", :undefined],
20
- :change_real_time => ["c6", :float],
21
- :after_hours_change_real_time => ["c8", :undefined],
22
- :dividend_per_share => ["d", :float],
23
- :last_trade_date => ["d1", :date],
24
- :trade_date => ["d2", :undefined],
25
- :earnings_per_share => ["e", :float],
26
- :error_indicator => ["e1", :string],
27
- :eps_estimate_current_year => ["e7", :float],
28
- :eps_estimate_next_year => ["e8", :float],
29
- :eps_estimate_next_quarter => ["e9", :float],
30
- :float_shares => ["f6", :float],
31
- :low => ["g", :float],
32
- :high => ["h", :float],
33
- :low_52_weeks => ["j", :float],
34
- :high_52_weeks => ["k", :float],
35
- :holdings_gain_percent => ["g1", :float],
36
- :annualized_gain => ["g3", :float],
37
- :holdings_gain => ["g4", :float],
38
- :holdings_gain_percent_realtime => ["g5", :float],
39
- :holdings_gain_realtime => ["g6", :float],
40
- :more_info => ["i", :string],
41
- :order_book => ["i5", :float],
42
- :market_capitalization => ["j1", :currency_amount],
43
- :market_cap_realtime => ["j3", :currency_amount],
44
- :ebitda => ["j4", :currency_amount],
45
- :change_From_52_week_low => ["j5", :float],
46
- :percent_change_from_52_week_low => ["j6", :float],
47
- :last_trade_realtime_withtime => ["k1", :string],
48
- :change_percent_realtime => ["k2", :string],
49
- :last_trade_size => ["k3", :integer],
50
- :change_from_52_week_high => ["k4", :float],
51
- :percent_change_from_52_week_high => ["k5", :float],
52
- :last_trade_with_time => ["l", :string],
53
- :last_trade_price => ["l1", :float],
54
- :close => ["l1", :float], # same as :last_trade_price
55
- :high_limit => ["l2", :float],
56
- :low_limit => ["l3", :float],
57
- :days_range => ["m", :float],
58
- :days_range_realtime => ["m2", :float],
59
- :moving_average_50_day => ["m3", :float],
60
- :moving_average_200_day => ["m4", :float],
61
- :change_from_200_day_moving_average => ["m5", :float],
62
- :percent_change_from_200_day_moving_average => ["m6", :float],
63
- :change_from_50_day_moving_average => ["m7", :float],
64
- :percent_change_from_50_day_moving_average => ["m8", :float],
65
- :name => ["n", :string],
66
- :notes => ["n4", :string],
67
- :open => ["o", :float],
68
- :previous_close => ["p", :float],
69
- :price_paid => ["p1", :float],
70
- :change_in_percent => ["p2", :float],
71
- :price_per_sales => ["p5", :float],
72
- :price_per_book => ["p6", :float],
73
- :ex_dividend_date => ["q", :date],
74
- :pe_ratio => ["p5", :float],
75
- :dividend_pay_date => ["r1", :undefined],
76
- :pe_ratio_realtime => ["r2", :float],
77
- :peg_ratio => ["r5", :float],
78
- :price_eps_estimate_current_year => ["r6", :float],
79
- :price_eps_Estimate_next_year => ["r7", :float],
80
- :symbol => ["s", :string],
81
- :shares_owned => ["s1", :float],
82
- :short_ratio => ["s7", :float],
83
- :last_trade_time => ["t1", :time],
84
- :trade_links => ["t6", :string],
85
- :ticker_trend => ["t7", :string],
86
- :one_year_target_price => ["t8", :float],
87
- :volume => ["v", :float],
88
- :holdings_value => ["v1", :undefined],
89
- :holdings_value_realtime => ["v7", :undefined],
90
- :weeks_range_52 => ["w", :float],
91
- :day_value_change => ["w1", :float],
92
- :day_value_change_realtime => ["w4", :string],
93
- :stock_exchange => ["x", :string],
94
- :dividend_yield => ["y", :float],
95
- :adjusted_close => [nil, :float] # this one only comes in historical quotes
21
+ :ask => "a",
22
+ :average_daily_volume => "a2",
23
+ :ask_size => "a5",
24
+ :bid => "b",
25
+ :ask_real_time => "b2",
26
+ :bid_real_time => "b3",
27
+ :book_value => "b4",
28
+ :bid_size => "b6",
29
+ :change_and_percent_change => "c",
30
+ :change => "c1",
31
+ :comission => "c3",
32
+ :change_real_time => "c6",
33
+ :after_hours_change_real_time => "c8",
34
+ :dividend_per_share => "d",
35
+ :last_trade_date => "d1",
36
+ :trade_date => "d2",
37
+ :earnings_per_share => "e",
38
+ :error_indicator => "e1",
39
+ :eps_estimate_current_year => "e7",
40
+ :eps_estimate_next_year => "e8",
41
+ :eps_estimate_next_quarter => "e9",
42
+ :float_shares => "f6",
43
+ :low => "g",
44
+ :high => "h",
45
+ :low_52_weeks => "j",
46
+ :high_52_weeks => "k",
47
+ :holdings_gain_percent => "g1",
48
+ :annualized_gain => "g3",
49
+ :holdings_gain => "g4",
50
+ :holdings_gain_percent_realtime => "g5",
51
+ :holdings_gain_realtime => "g6",
52
+ :more_info => "i",
53
+ :order_book => "i5",
54
+ :market_capitalization => "j1",
55
+ :market_cap_realtime => "j3",
56
+ :ebitda => "j4",
57
+ :change_From_52_week_low => "j5",
58
+ :percent_change_from_52_week_low => "j6",
59
+ :last_trade_realtime_withtime => "k1",
60
+ :change_percent_realtime => "k2",
61
+ :last_trade_size => "k3",
62
+ :change_from_52_week_high => "k4",
63
+ :percent_change_from_52_week_high => "k5",
64
+ :last_trade_with_time => "l",
65
+ :last_trade_price => "l1",
66
+ :close => "l1",
67
+ :high_limit => "l2",
68
+ :low_limit => "l3",
69
+ :days_range => "m",
70
+ :days_range_realtime => "m2",
71
+ :moving_average_50_day => "m3",
72
+ :moving_average_200_day => "m4",
73
+ :change_from_200_day_moving_average => "m5",
74
+ :percent_change_from_200_day_moving_average => "m6",
75
+ :change_from_50_day_moving_average => "m7",
76
+ :percent_change_from_50_day_moving_average => "m8",
77
+ :name => "n",
78
+ :notes => "n4",
79
+ :open => "o",
80
+ :previous_close => "p",
81
+ :price_paid => "p1",
82
+ :change_in_percent => "p2",
83
+ :price_per_sales => "p5",
84
+ :price_per_book => "p6",
85
+ :ex_dividend_date => "q",
86
+ :pe_ratio => "r",
87
+ :dividend_pay_date => "r1",
88
+ :pe_ratio_realtime => "r2",
89
+ :peg_ratio => "r5",
90
+ :price_eps_estimate_current_year => "r6",
91
+ :price_eps_Estimate_next_year => "r7",
92
+ :symbol => "s",
93
+ :shares_owned => "s1",
94
+ :short_ratio => "s7",
95
+ :last_trade_time => "t1",
96
+ :trade_links => "t6",
97
+ :ticker_trend => "t7",
98
+ :one_year_target_price => "t8",
99
+ :volume => "v",
100
+ :holdings_value => "v1",
101
+ :holdings_value_realtime => "v7",
102
+ :weeks_range_52 => "w",
103
+ :day_value_change => "w1",
104
+ :day_value_change_realtime => "w4",
105
+ :stock_exchange => "x",
106
+ :dividend_yield => "y",
107
+ :adjusted_close => nil # this one only comes in historical quotes
96
108
  }
97
-
109
+
98
110
  HISTORICAL_MODES = {
99
111
  :daily => "d",
100
112
  :weekly => "w",
@@ -102,98 +114,118 @@ require 'ostruct'
102
114
  :dividends_only => "v"
103
115
  }
104
116
 
105
- ROWS_PER_REQUEST = 50
117
+ SYMBOLS_PER_REQUEST = 50
106
118
 
107
119
  # retrieve the quote data (an OpenStruct per quote)
108
120
  # the options param can be used to specify the following attributes:
109
121
  # :raw - if true, each column will be converted (to numbers, dates, etc)
110
- def self.quotes(symbols_array, columns_array = [:symbol, :last_trade_price, :last_trade_date, :change, :previous_close], options = { :raw => true })
111
- ret = []
112
- cols = columns_array.collect { |c| COLUMNS[c][0] }.join
113
- types = columns_array.collect { |c| COLUMNS[c][1] }.join if options[:raw]
114
-
115
- i = 0
116
- k = 0
117
- while i < symbols_array.size
118
- subset = symbols_array[i..i+ROWS_PER_REQUEST]
119
- symb_str = subset.collect { |s| "#{s}" }.join("+")
120
-
121
- lines = read_lines(symb_str, cols)
122
- for line in lines
123
- ret << extract_data(line, symbols_array[k], columns_array, options)
124
- k+=1
125
- end
122
+ def self.quotes(symbols_array, columns_array = [:symbol, :last_trade_price, :last_trade_date, :change, :previous_close], options = { })
123
+ options[:raw] ||= true
126
124
 
127
- i += ROWS_PER_REQUEST+1
128
- end
125
+ ret = []
126
+ symbols_array.each_slice(SYMBOLS_PER_REQUEST) do |symbols|
127
+ read_quotes(symbols.join("+"), columns_array).map do |row|
128
+ ret << OpenStruct.new(row.to_hash)
129
+ end
130
+ end
131
+ ret
132
+ end
129
133
 
130
- return ret
134
+ def self.quote(symbol, columns_array = [:symbol, :last_trade_price, :last_trade_date, :change, :previous_close], options = { })
135
+ options[:raw] ||= true
136
+ quotes([symbol], columns_array, options).first
131
137
  end
132
-
133
- def self.historical_quotes(symbol, start_date, end_date, options = { :raw => true, :period => :daily })
134
- options[:period] ||= :daily
135
- lines = read_historical(symbol, start_date, end_date, options)
136
- ret = []
137
-
138
- if options[:period] == :dividends_only
139
- cols = [:dividend_pay_date, :dividend_yield]
140
- else
141
- cols = [:trade_date, :open, :high, :low, :close, :volume, :adjusted_close]
142
- end
143
-
144
- for line in lines
145
- ret << extract_data(line, symbol, cols, options)
146
- end
147
-
148
- return ret
138
+
139
+ def self.historical_quotes(symbol, options = {})
140
+ options[:raw] ||= true
141
+ options[:period] ||= :daily
142
+ read_historical(symbol, options).map do |row|
143
+ OpenStruct.new(row.to_hash.merge(:symbol => symbol))
144
+ end
149
145
  end
150
-
151
- private
152
-
153
- def self.extract_data(raw_line, symbol, columns_array, options)
154
- datamap = {}
155
- datamap[:symbol] = symbol
156
- data = raw_line.split(',')
157
-
158
- for j in (0..data.size-1)
159
- if !options[:raw]
160
- datamap[columns_array[j]] = format(data[j], COLUMNS[columns_array[j]][1])
161
- else
162
- datamap[columns_array[j]] = data[j]
163
- end
164
- end
165
146
 
166
- OpenStruct.new(datamap)
147
+ def self.symbols(query)
148
+ ret = []
149
+ read_symbols(query).each do |row|
150
+ ret << OpenStruct.new(row)
151
+ end
152
+ ret
167
153
  end
168
-
169
- def self.format(str, type)
170
- case type
171
- when :float then str.to_f
172
- when :integer then str.to_i
173
- #when :date then DateTime::parse(str)
174
- #when :time then Time.parse(str)
175
- else str
154
+
155
+ def self.splits(symbol, options = {})
156
+ rows = read_splits(symbol, options).select{|row| row[0] == 'SPLIT'}
157
+ rows.map do |row|
158
+ type, date, value = row
159
+ after, before = value.split(':')
160
+ OpenStruct.new(:symbol => symbol, :date => Date.strptime(date.strip, '%Y%m%d'), :before => before.to_i, :after => after.to_i)
176
161
  end
177
162
  end
178
-
179
- def self.read_lines(symb_str, cols)
180
- conn = open("http://finance.yahoo.com/d/quotes.csv?s=#{symb_str}&f=#{cols}")
181
- lines = conn.read
182
-
183
- lines.split("\r\n")
163
+
164
+ private
165
+
166
+ def self.read_quotes(symb_str, cols)
167
+ columns = "#{cols.map {|col| COLUMNS[col] }.join('')}"
168
+ conn = open("http://download.finance.yahoo.com/d/quotes.csv?s=#{URI.escape(symb_str)}&f=#{columns}")
169
+ CSV.parse(conn.read, :headers => cols)
170
+ end
171
+
172
+ def self.read_historical(symbol, options)
173
+ params = {
174
+ :s => URI.escape(symbol),
175
+ :g => HISTORICAL_MODES[options[:period]],
176
+ :ignore => '.csv',
177
+ }
178
+ if options[:start_date]
179
+ params[:a] = options[:start_date].month-1
180
+ params[:b] = options[:start_date].day
181
+ params[:c] = options[:start_date].year
182
+ end
183
+ if options[:end_date]
184
+ params[:d] = options[:end_date].month-1
185
+ params[:e] = options[:end_date].day
186
+ params[:f] = options[:end_date].year
187
+ end
188
+
189
+ url = "http://ichart.finance.yahoo.com/table.csv?#{params.map{|k, v| "#{k}=#{v}"}.join('&')}"
190
+ conn = open(url)
191
+ cols =
192
+ if options[:period] == :dividends_only
193
+ [:dividend_pay_date, :dividend_yield]
194
+ else
195
+ [:trade_date, :open, :high, :low, :close, :volume, :adjusted_close]
196
+ end
197
+ result = CSV.parse(conn.read, :headers => cols) #:first_row, :header_converters => :symbol)
198
+ result.delete(0) # drop returned header
199
+ result
184
200
  end
185
-
186
- def self.read_historical(symbol, start_date, end_date, options)
187
- url = "http://ichart.finance.yahoo.com/table.csv?s=#{symbol}&d=#{end_date.month-1}&e=#{end_date.day}&f=#{end_date.year}&g=#{HISTORICAL_MODES[options[:period]]}&a=#{start_date.month-1}&b=#{start_date.day}&c=#{start_date.year}&ignore=.csv"
188
- begin
189
- conn = open(url)
190
- rescue
191
- return []
201
+
202
+ def self.read_splits(symbol, options)
203
+ params = {
204
+ :s => URI.escape(symbol),
205
+ :g => 'v'
206
+ }
207
+ if options[:start_date]
208
+ params[:a] = options[:start_date].month-1
209
+ params[:b] = options[:start_date].day
210
+ params[:c] = options[:start_date].year
192
211
  end
193
- lines = conn.read
212
+ if options[:end_date]
213
+ params[:d] = options[:end_date].month-1
214
+ params[:e] = options[:end_date].day
215
+ params[:f] = options[:end_date].year
216
+ end
217
+
218
+ url = "http://ichart.finance.yahoo.com/x?#{params.map{|k, v| "#{k}=#{v}"}.join('&')}"
219
+ conn = open(url)
220
+ CSV.parse(conn.read)
221
+ end
194
222
 
195
- all_lines = lines.split("\n")
196
- return all_lines[1..all_lines.size-1]
223
+ def self.read_symbols(query)
224
+ conn = open("http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=#{query}&callback=YAHOO.Finance.SymbolSuggest.ssCallback")
225
+ result = conn.read
226
+ result.sub!('YAHOO.Finance.SymbolSuggest.ssCallback(', '').chomp!(')')
227
+ json_result = JSON.parse(result)
228
+ json_result["ResultSet"]["Result"]
197
229
  end
198
-
199
- end
230
+
231
+ end
metadata CHANGED
@@ -1,49 +1,48 @@
1
- --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
1
+ --- !ruby/object:Gem::Specification
4
2
  name: yahoo-finance
5
- version: !ruby/object:Gem::Version
6
- version: 0.0.2
7
- date: 2007-08-05 00:00:00 -03:00
8
- summary: A wrapper to Yahoo! Finance market data (quotes and exchange rates) feed
9
- require_paths:
10
- - lib
11
- email: herval@hervalicio.us
12
- homepage: http://hervalicio.us/blog
13
- rubyforge_project:
14
- description:
15
- autorequire: yahoo_finance
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: false
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
- authors:
6
+ authors:
30
7
  - Herval Freire
31
- files:
32
- - lib/yahoo_finance.rb
33
- - README
34
- - HISTORY
35
- test_files: []
36
-
37
- rdoc_options: []
38
-
39
- extra_rdoc_files:
40
- - README
41
- - HISTORY
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: herval@hervalicio.us
42
15
  executables: []
43
-
44
16
  extensions: []
45
-
17
+ extra_rdoc_files:
18
+ - README.md
19
+ - HISTORY
20
+ files:
21
+ - HISTORY
22
+ - README.md
23
+ - lib/yahoo-finance.rb
24
+ - lib/yahoo_finance.rb
25
+ homepage: http://hervalicio.us/blog
26
+ licenses: []
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
46
42
  requirements: []
47
-
48
- dependencies: []
49
-
43
+ rubyforge_project:
44
+ rubygems_version: 2.2.2
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: A wrapper to Yahoo! Finance market data (quotes and exchange rates) feed
48
+ test_files: []