yahoo-finance 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +105 -0
- data/bin/yahoo_finance.rb +133 -0
- metadata +47 -0
data/README
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
Ruby's Yahoo Finance Wrapper
|
2
|
+
============================
|
3
|
+
|
4
|
+
A dead simple wrapper for yahoo finance quotes end-point.
|
5
|
+
|
6
|
+
|
7
|
+
Usage:
|
8
|
+
Just pass an array of symbols (stock names, indexes, exchange rates) and a list of fields you want:
|
9
|
+
|
10
|
+
data = Yahoo::Finance.quotes(["BVSP", "NATU3.SA", "USDJPY=X"], [:ask, :bid, :last_trade_date])
|
11
|
+
puts data[0].symbol + " value is: " + data[0].ask
|
12
|
+
|
13
|
+
|
14
|
+
The full list of fields follows:
|
15
|
+
|
16
|
+
:ask
|
17
|
+
:average_daily_volume
|
18
|
+
:ask_size
|
19
|
+
:bid
|
20
|
+
:ask_real_time
|
21
|
+
:bid_real_time
|
22
|
+
:book_value b4
|
23
|
+
:bid_size b6
|
24
|
+
:chance_and_percent_change
|
25
|
+
:change
|
26
|
+
:comission
|
27
|
+
:change_real_time
|
28
|
+
:after_hours_change_real_time
|
29
|
+
:dividend_per_share
|
30
|
+
:last_trade_date
|
31
|
+
:trade_date
|
32
|
+
:earnings_per_share
|
33
|
+
:error_indicator
|
34
|
+
:eps_estimate_current_year
|
35
|
+
:eps_estimate_next_year
|
36
|
+
:eps_estimate_next_quarter
|
37
|
+
:float_shares
|
38
|
+
:days_low
|
39
|
+
:days_high
|
40
|
+
:low_52_weeks
|
41
|
+
:high_52_weeks
|
42
|
+
:holdings_gain_percent
|
43
|
+
:annualized_gain
|
44
|
+
:holdings_gain
|
45
|
+
:holdings_gain_percent_realtime
|
46
|
+
:holdings_gain_realtime
|
47
|
+
:more_info
|
48
|
+
:order_book
|
49
|
+
:market_capitalization
|
50
|
+
:market_cap_realtime
|
51
|
+
:ebitda
|
52
|
+
:change_From_52_week_low
|
53
|
+
:percent_change_from_52_week_low
|
54
|
+
:last_trade_realtime_withtime
|
55
|
+
:change_percent_realtime
|
56
|
+
:last_trade_size
|
57
|
+
:change_from_52_week_high
|
58
|
+
:percent_change_from_52_week_high
|
59
|
+
:last_trade_with_time
|
60
|
+
:last_trade_price_only
|
61
|
+
:high_limit
|
62
|
+
:low_limit
|
63
|
+
:days_range
|
64
|
+
:days_range_realtime
|
65
|
+
:moving_average_50_day
|
66
|
+
:moving_average_200_day
|
67
|
+
:change_from_200_day_moving_average
|
68
|
+
:percent_change_from_200_day_moving_average
|
69
|
+
:change_from_50_day_moving_average
|
70
|
+
:percent_change_from_50_day_moving_average
|
71
|
+
:name
|
72
|
+
:notes
|
73
|
+
:open
|
74
|
+
:previous_close
|
75
|
+
:price_paid
|
76
|
+
:change_in_percent
|
77
|
+
:price_per_sales
|
78
|
+
:price_per_book
|
79
|
+
:ex_dividend_date
|
80
|
+
:pe_ratio
|
81
|
+
:dividend_pay_date
|
82
|
+
:pe_ratio_realtime
|
83
|
+
:peg_ratio
|
84
|
+
:price_eps_estimate_current_year
|
85
|
+
:price_eps_Estimate_next_year
|
86
|
+
:symbol
|
87
|
+
:shares_owned
|
88
|
+
:short_ratio
|
89
|
+
:last_trade_time
|
90
|
+
:trade_links
|
91
|
+
:ticker_trend
|
92
|
+
:one_year_target_price
|
93
|
+
:volume
|
94
|
+
:holdings_value
|
95
|
+
:holdings_value_realtime
|
96
|
+
:weeks_range_52
|
97
|
+
:day_value_change
|
98
|
+
:day_value_change_realtime
|
99
|
+
:stock_exchange
|
100
|
+
:dividend_yield
|
101
|
+
|
102
|
+
|
103
|
+
Enjoy! :-)
|
104
|
+
|
105
|
+
- Herval (contact@hervalicio.us)
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module Yahoo
|
5
|
+
|
6
|
+
class Finance
|
7
|
+
|
8
|
+
VERSION = '0.0.1'
|
9
|
+
|
10
|
+
@@columns = {
|
11
|
+
:ask => "a",
|
12
|
+
:average_daily_volume => "a2",
|
13
|
+
:ask_size => "a5",
|
14
|
+
:bid => "b",
|
15
|
+
:ask_real_time => "b2",
|
16
|
+
:bid_real_time => "b3",
|
17
|
+
:book_value => "b4",
|
18
|
+
:bid_size => "b6",
|
19
|
+
:chance_and_percent_change => "c",
|
20
|
+
:change => "c1",
|
21
|
+
:comission => "c3",
|
22
|
+
:change_real_time => "c6",
|
23
|
+
:after_hours_change_real_time => "c8",
|
24
|
+
:dividend_per_share => "d",
|
25
|
+
:last_trade_date => "d1",
|
26
|
+
:trade_date => "d2",
|
27
|
+
:earnings_per_share => "e",
|
28
|
+
:error_indicator => "e1",
|
29
|
+
:eps_estimate_current_year => "e7",
|
30
|
+
:eps_estimate_next_year => "e8",
|
31
|
+
:eps_estimate_next_quarter => "e9",
|
32
|
+
:float_shares => "f6",
|
33
|
+
:days_low => "g",
|
34
|
+
:days_high => "h",
|
35
|
+
:low_52_weeks => "j",
|
36
|
+
:high_52_weeks => "k",
|
37
|
+
:holdings_gain_percent => "g1",
|
38
|
+
:annualized_gain => "g3",
|
39
|
+
:holdings_gain => "g4",
|
40
|
+
:holdings_gain_percent_realtime => "g5",
|
41
|
+
:holdings_gain_realtime => "g6",
|
42
|
+
:more_info => "i",
|
43
|
+
:order_book => "i5",
|
44
|
+
:market_capitalization => "j1",
|
45
|
+
:market_cap_realtime => "j3",
|
46
|
+
:ebitda => "j4",
|
47
|
+
:change_From_52_week_low => "j5",
|
48
|
+
:percent_change_from_52_week_low => "j6",
|
49
|
+
:last_trade_realtime_withtime => "k1",
|
50
|
+
:change_percent_realtime => "k2",
|
51
|
+
:last_trade_size => "k3",
|
52
|
+
:change_from_52_week_high => "k4",
|
53
|
+
:percent_change_from_52_week_high => "k5",
|
54
|
+
:last_trade_with_time => "l",
|
55
|
+
:last_trade_price_only => "l1",
|
56
|
+
:high_limit => "l2",
|
57
|
+
:low_limit => "l3",
|
58
|
+
:days_range => "m",
|
59
|
+
:days_range_realtime => "m2",
|
60
|
+
:moving_average_50_day => "m3",
|
61
|
+
:moving_average_200_day => "m4",
|
62
|
+
:change_from_200_day_moving_average => "m5",
|
63
|
+
:percent_change_from_200_day_moving_average => "m6",
|
64
|
+
:change_from_50_day_moving_average => "m7",
|
65
|
+
:percent_change_from_50_day_moving_average => "m8",
|
66
|
+
:name => "n",
|
67
|
+
:notes => "n4",
|
68
|
+
:open => "o",
|
69
|
+
:previous_close => "p",
|
70
|
+
:price_paid => "p1",
|
71
|
+
:change_in_percent => "p2",
|
72
|
+
:price_per_sales => "p5",
|
73
|
+
:price_per_book => "p6",
|
74
|
+
:ex_dividend_date => "q",
|
75
|
+
:pe_ratio => "p5",
|
76
|
+
:dividend_pay_date => "r1",
|
77
|
+
:pe_ratio_realtime => "r2",
|
78
|
+
:peg_ratio => "r5",
|
79
|
+
:price_eps_estimate_current_year => "r6",
|
80
|
+
:price_eps_Estimate_next_year => "r7",
|
81
|
+
:symbol => "s",
|
82
|
+
:shares_owned => "s1",
|
83
|
+
:short_ratio => "s7",
|
84
|
+
:last_trade_time => "t1",
|
85
|
+
:trade_links => "t6",
|
86
|
+
:ticker_trend => "t7",
|
87
|
+
:one_year_target_price => "t8",
|
88
|
+
:volume => "v",
|
89
|
+
:holdings_value => "v1",
|
90
|
+
:holdings_value_realtime => "v7",
|
91
|
+
:weeks_range_52 => "w",
|
92
|
+
:day_value_change => "w1",
|
93
|
+
:day_value_change_realtime => "w4",
|
94
|
+
:stock_exchange => "x",
|
95
|
+
:dividend_yield => "y"
|
96
|
+
}
|
97
|
+
|
98
|
+
ROWS_PER_REQUEST = 50
|
99
|
+
|
100
|
+
def self.quotes(symbols_array, columns_array = [:symbol, :ask, :bid])
|
101
|
+
ret = []
|
102
|
+
cols = columns_array.collect { |c| @@columns[c] }.join
|
103
|
+
|
104
|
+
i = 0
|
105
|
+
k = 0
|
106
|
+
while i < symbols_array.size
|
107
|
+
subset = symbols_array[i..i+ROWS_PER_REQUEST]
|
108
|
+
symb_str = subset.collect { |s| "#{s}" }.join("+")
|
109
|
+
|
110
|
+
conn = open("http://finance.yahoo.com/d/quotes.csv?s=#{symb_str}&f=#{cols}")
|
111
|
+
lines = conn.read.split
|
112
|
+
for line in lines
|
113
|
+
datamap = {}
|
114
|
+
datamap[:symbol] = symbols_array[k]
|
115
|
+
data = line.split(',')
|
116
|
+
|
117
|
+
for j in (0..data.size-1)
|
118
|
+
datamap[columns_array[j]] = data[j]
|
119
|
+
end
|
120
|
+
|
121
|
+
ret << OpenStruct.new(datamap)
|
122
|
+
k+=1
|
123
|
+
end
|
124
|
+
|
125
|
+
i += ROWS_PER_REQUEST+1
|
126
|
+
end
|
127
|
+
|
128
|
+
return ret
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
4
|
+
name: yahoo-finance
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2007-08-04 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:
|
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:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Herval Freire
|
31
|
+
files:
|
32
|
+
- bin/yahoo_finance.rb
|
33
|
+
- README
|
34
|
+
test_files: []
|
35
|
+
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
extra_rdoc_files:
|
39
|
+
- README
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
requirements: []
|
45
|
+
|
46
|
+
dependencies: []
|
47
|
+
|