yahoo-finance 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -9
- data/lib/yahoo-finance.rb +95 -37
- data/lib/yahoo-finance/version.rb +1 -1
- metadata +59 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4d05824e6ec9455f7431eb7450405a4f187502c
|
4
|
+
data.tar.gz: 53b32872affff1bd7a1ba6153b73f62aac280852
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69bbfa32a532c46ee3360b58a48492b74638e4816513359d7b7c212c6909fc317d92e9100cd63d1302aaa52ac94dc759ee740215fc4cff1af349afbdaf215c7b
|
7
|
+
data.tar.gz: 5dfa9bbe070a5bcce32df9ffedb1257d9e2880c8dcbc052bef866a47a4d557aae49f1d97a3fefa36c042873c69d2bdbce287c04509514c86ee68f3c0dd759918
|
data/README.md
CHANGED
@@ -3,14 +3,10 @@ A dead simple wrapper for yahoo finance quotes end-point.
|
|
3
3
|
|
4
4
|
## Installation:
|
5
5
|
|
6
|
-
|
7
|
-
`require 'yahoo-finance'`
|
6
|
+
Just add it to your `Gemfile`:
|
8
7
|
|
9
|
-
|
8
|
+
`gem 'yahoo-finance'`
|
10
9
|
|
11
|
-
`gem 'yahoo-finance', git: 'https://github.com/herval/yahoo-finance.git'`
|
12
|
-
|
13
|
-
`require: 'yahoo-finance'`
|
14
10
|
|
15
11
|
## Usage:
|
16
12
|
|
@@ -39,7 +35,7 @@ data[0].ask # This is now a float
|
|
39
35
|
|
40
36
|
The full list of fields follows:
|
41
37
|
|
42
|
-
```
|
38
|
+
```ruby
|
43
39
|
:after_hours_change_real_time
|
44
40
|
:annualized_gain
|
45
41
|
:ask
|
@@ -117,6 +113,8 @@ The full list of fields follows:
|
|
117
113
|
:price_paid
|
118
114
|
:price_per_book
|
119
115
|
:price_per_sales
|
116
|
+
:revenue
|
117
|
+
:shares_outstanding
|
120
118
|
:shares_owned
|
121
119
|
:short_ratio
|
122
120
|
:stock_exchange
|
@@ -133,7 +131,7 @@ The full list of fields follows:
|
|
133
131
|
Create a YahooFinance::Client instance
|
134
132
|
|
135
133
|
```ruby
|
136
|
-
yahoo_client =
|
134
|
+
yahoo_client = YahooFinance::Client.new
|
137
135
|
```
|
138
136
|
|
139
137
|
Calling symbols_by_market method (symbols_by_market(country, stock_market))
|
@@ -143,7 +141,7 @@ Note: Can only be called with US Stock Markets for now.
|
|
143
141
|
*Important: This data comes directly from NASDAQ's CSV endpoints, NOT Yahoo Finance*. It might be extracted into a different Gem in the future.
|
144
142
|
|
145
143
|
```ruby
|
146
|
-
yahoo_client.
|
144
|
+
yahoo_client.symbols_by_market('us', 'nyse') # Only US Stock Markets For Now
|
147
145
|
```
|
148
146
|
|
149
147
|
This method returns an array of symbols that can be used with the quotes method
|
data/lib/yahoo-finance.rb
CHANGED
@@ -11,44 +11,99 @@ module YahooFinance
|
|
11
11
|
include YahooFinance::FinanceUtils
|
12
12
|
|
13
13
|
COLUMNS = {
|
14
|
-
ask: "a",
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
14
|
+
ask: "a",
|
15
|
+
average_daily_volume: "a2",
|
16
|
+
ask_size: "a5",
|
17
|
+
bid: "b",
|
18
|
+
ask_real_time: "b2",
|
19
|
+
bid_real_time: "b3",
|
20
|
+
book_value: "b4",
|
21
|
+
bid_size: "b6",
|
22
|
+
change_and_percent_change: "c",
|
23
|
+
change: "c1",
|
24
|
+
comission: "c3",
|
25
|
+
change_real_time: "c6",
|
26
|
+
after_hours_change_real_time: "c8",
|
27
|
+
dividend_per_share: "d",
|
28
|
+
last_trade_date: "d1",
|
29
|
+
trade_date: "d2",
|
30
|
+
earnings_per_share: "e",
|
31
|
+
error_indicator: "e1",
|
32
|
+
eps_estimate_current_year: "e7",
|
33
|
+
eps_estimate_next_year: "e8",
|
34
|
+
eps_estimate_next_quarter: "e9",
|
35
|
+
float_shares: "f6",
|
36
|
+
low: "g", high: "h",
|
37
|
+
low_52_weeks: "j",
|
38
|
+
high_52_weeks: "k",
|
39
|
+
holdings_gain_percent: "g1",
|
40
|
+
annualized_gain: "g3",
|
41
|
+
holdings_gain: "g4",
|
42
|
+
holdings_gain_percent_realtime: "g5",
|
43
|
+
holdings_gain_realtime: "g6",
|
44
|
+
more_info: "i",
|
45
|
+
order_book: "i5",
|
46
|
+
market_capitalization: "j1",
|
47
|
+
shares_outstanding: "j2",
|
48
|
+
market_cap_realtime: "j3",
|
49
|
+
ebitda: "j4",
|
50
|
+
change_From_52_week_low: "j5",
|
51
|
+
percent_change_from_52_week_low: "j6",
|
52
|
+
last_trade_realtime_withtime: "k1",
|
53
|
+
change_percent_realtime: "k2",
|
54
|
+
last_trade_size: "k3",
|
55
|
+
change_from_52_week_high: "k4",
|
56
|
+
percent_change_from_52_week_high: "k5",
|
57
|
+
last_trade_with_time: "l",
|
58
|
+
last_trade_price: "l1",
|
59
|
+
close: "l1",
|
60
|
+
high_limit: "l2",
|
61
|
+
low_limit: "l3",
|
62
|
+
days_range: "m",
|
63
|
+
days_range_realtime: "m2",
|
64
|
+
moving_average_50_day: "m3",
|
65
|
+
moving_average_200_day: "m4",
|
66
|
+
change_from_200_day_moving_average: "m5",
|
34
67
|
percent_change_from_200_day_moving_average: "m6",
|
35
68
|
change_from_50_day_moving_average: "m7",
|
36
|
-
percent_change_from_50_day_moving_average: "m8",
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
69
|
+
percent_change_from_50_day_moving_average: "m8",
|
70
|
+
name: "n",
|
71
|
+
notes: "n4",
|
72
|
+
open: "o", previous_close: "p",
|
73
|
+
price_paid: "p1",
|
74
|
+
change_in_percent: "p2",
|
75
|
+
price_per_sales: "p5",
|
76
|
+
price_per_book: "p6",
|
77
|
+
ex_dividend_date: "q",
|
78
|
+
pe_ratio: "r",
|
79
|
+
dividend_pay_date: "r1",
|
80
|
+
pe_ratio_realtime: "r2",
|
81
|
+
peg_ratio: "r5",
|
82
|
+
price_eps_estimate_current_year: "r6",
|
83
|
+
price_eps_Estimate_next_year: "r7",
|
84
|
+
symbol: "s",
|
85
|
+
shares_owned: "s1",
|
86
|
+
revenue: "s6",
|
87
|
+
short_ratio: "s7", last_trade_time: "t1",
|
88
|
+
trade_links: "t6",
|
89
|
+
ticker_trend: "t7",
|
90
|
+
one_year_target_price: "t8", volume: "v",
|
91
|
+
holdings_value: "v1",
|
92
|
+
holdings_value_realtime: "v7",
|
93
|
+
weeks_range_52: "w",
|
94
|
+
day_value_change: "w1",
|
95
|
+
day_value_change_realtime: "w4",
|
96
|
+
stock_exchange: "x",
|
97
|
+
dividend_yield: "y",
|
98
|
+
adjusted_close: nil
|
47
99
|
# only in historical quotes ^
|
48
100
|
}
|
49
101
|
|
50
102
|
HISTORICAL_MODES = {
|
51
|
-
daily: "d",
|
103
|
+
daily: "d",
|
104
|
+
weekly: "w",
|
105
|
+
monthly: "m",
|
106
|
+
dividends_only: "v"
|
52
107
|
}
|
53
108
|
|
54
109
|
SYMBOLS_PER_REQUEST = 50
|
@@ -64,6 +119,9 @@ module YahooFinance
|
|
64
119
|
ret = []
|
65
120
|
symbols_array.each_slice(SYMBOLS_PER_REQUEST) do |symbols|
|
66
121
|
read_quotes(symbols.join("+"), columns_array).map do |row|
|
122
|
+
if options[:na_as_nil]
|
123
|
+
row.each{ |key, value| row[key] = nil if value == 'N/A' }
|
124
|
+
end
|
67
125
|
ret << OpenStruct.new(row.to_hash)
|
68
126
|
end
|
69
127
|
end
|
@@ -109,7 +167,7 @@ module YahooFinance
|
|
109
167
|
|
110
168
|
def read_quotes(symb_str, cols)
|
111
169
|
columns = "#{cols.map { |col| COLUMNS[col] }.join("")}"
|
112
|
-
conn = open("
|
170
|
+
conn = open("https://download.finance.yahoo.com/d/quotes.csv?s=#{URI.escape(symb_str)}&f=#{columns}")
|
113
171
|
CSV.parse(conn.read, headers: cols)
|
114
172
|
end
|
115
173
|
|
@@ -128,7 +186,7 @@ module YahooFinance
|
|
128
186
|
params[:f] = options[:end_date].year
|
129
187
|
end
|
130
188
|
|
131
|
-
url = "
|
189
|
+
url = "https://ichart.finance.yahoo.com/table.csv?#{params.map{|k, v| "#{k}=#{v}"}.join("&")}"
|
132
190
|
conn = open(url)
|
133
191
|
cols = if options[:period] == :dividends_only
|
134
192
|
[:dividend_pay_date, :dividend_yield]
|
@@ -156,15 +214,15 @@ module YahooFinance
|
|
156
214
|
params[:f] = options[:end_date].year
|
157
215
|
end
|
158
216
|
|
159
|
-
url = "
|
217
|
+
url = "https://ichart.finance.yahoo.com/x?#{params.map{|k, v| "#{k}=#{v}"}.join("&")}"
|
160
218
|
conn = open(url)
|
161
219
|
CSV.parse(conn.read)
|
162
220
|
end
|
163
221
|
|
164
222
|
def read_symbols(query)
|
165
|
-
conn = open("http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=#{query}&callback=YAHOO.Finance.SymbolSuggest.ssCallback")
|
223
|
+
conn = open("http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=#{query}®ion=US&lang=en-US&callback=YAHOO.Finance.SymbolSuggest.ssCallback")
|
166
224
|
result = conn.read
|
167
|
-
result.sub!("YAHOO.Finance.SymbolSuggest.ssCallback(", "").chomp!(")")
|
225
|
+
result.sub!("YAHOO.Finance.SymbolSuggest.ssCallback(", "").chomp!(");")
|
168
226
|
json_result = JSON.parse(result)
|
169
227
|
json_result["ResultSet"]["Result"]
|
170
228
|
end
|
metadata
CHANGED
@@ -1,15 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yahoo-finance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Herval Freire
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2016-10-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: test-unit
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
13
69
|
description:
|
14
70
|
email: herval@hervalicio.us
|
15
71
|
executables: []
|