nas-yahoo_stock 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +11 -2
- data/README.rdoc +51 -70
- data/Rakefile +7 -17
- data/lib/yahoo_stock/interface/history.rb +6 -5
- data/spec/spec_helper.rb +2 -1
- data/spec/yahoo_stock/interface/history_spec.rb +2 -2
- metadata +30 -4
data/History.txt
CHANGED
@@ -36,7 +36,7 @@
|
|
36
36
|
=== 1.0.1 2009-09-10
|
37
37
|
|
38
38
|
* 1 addition:
|
39
|
-
* adds feature to
|
39
|
+
* adds feature to retrieve historical stock data
|
40
40
|
|
41
41
|
=== 1.0.2 2009-10-04
|
42
42
|
Major changes in the public API. Check the README.rdoc file and individual classes for more information
|
@@ -78,4 +78,13 @@ Major changes in the public API. Check the README.rdoc file and individual class
|
|
78
78
|
=== 1.0.5 2010-05-07
|
79
79
|
|
80
80
|
* 1 change:
|
81
|
-
* made the case statement in YahooStock::Interface::History on line 86 ruby 1.9.1 compatible
|
81
|
+
* made the case statement in YahooStock::Interface::History on line 86 ruby 1.9.1 compatible
|
82
|
+
|
83
|
+
=== 1.0.6 2010-11-13
|
84
|
+
|
85
|
+
* 2 addition:
|
86
|
+
* adds dividend query option by Ryan Sandridge
|
87
|
+
* adds cucumber rake task
|
88
|
+
|
89
|
+
* 1 changes:
|
90
|
+
* Make sure all tests are run with rspec 2.1.0
|
data/README.rdoc
CHANGED
@@ -6,8 +6,8 @@
|
|
6
6
|
|
7
7
|
Provides an interface to yahoo finance to get stock related data. For instance, latest trade related data, volume, 50 day moving average, market cap, etc, virtually any thing that yahoo finance provides.
|
8
8
|
|
9
|
-
If you don't know the stock / scrip symbol of the company then you can find that out by using the YahooStock::ScripSymbol class. The methods are mentioned in the Usage section below. For instance, YHOO for yahoo, GOOG for google, etc.
|
10
|
-
The kind of parameters to be passed can be found after initializing the
|
9
|
+
If you don't know the stock / scrip symbol of the company then you can find that out by using the YahooStock::ScripSymbol class. The methods are mentioned in the Usage section below. For instance, YHOO for yahoo, GOOG for google, etc.
|
10
|
+
The kind of parameters to be passed can be found after initializing the
|
11
11
|
YahooStock::Quote object and passing valid_parameters message to the quote object, example is given below in the USAGE section.
|
12
12
|
|
13
13
|
For details : http://nasir.wordpress.com/2009/10/28/ruby-gem-for-finance-data
|
@@ -22,108 +22,82 @@ For details : http://nasir.wordpress.com/2009/10/28/ruby-gem-for-finance-data
|
|
22
22
|
|
23
23
|
== USAGE:
|
24
24
|
|
25
|
-
require 'rubygems'
|
25
|
+
require 'rubygems'
|
26
|
+
require 'yahoo_stock'
|
26
27
|
|
27
|
-
|
28
|
+
* Initialize quote object:
|
28
29
|
|
29
|
-
|
30
|
+
quote = YahooStock::Quote.new(:stock_symbols => ['YHOO', 'GOOG'])
|
30
31
|
|
31
|
-
|
32
|
+
* To view the valid parameters that can be passed:
|
32
33
|
|
33
|
-
|
34
|
+
quote.valid_parameters
|
34
35
|
|
35
|
-
|
36
|
+
* To view the current parameters used:
|
36
37
|
|
37
|
-
|
38
|
+
quote.current_parameters
|
38
39
|
|
39
|
-
|
40
|
+
* To view the current stock symbols used:
|
40
41
|
|
41
|
-
|
42
|
+
quote.current_symbols
|
42
43
|
|
43
|
-
|
44
|
+
* To add more stocks to the list:
|
44
45
|
|
45
|
-
|
46
|
+
quote.add_symbols('MSFT', 'AAPL')
|
46
47
|
|
47
|
-
|
48
|
+
* To remove stocks from list:
|
48
49
|
|
49
|
-
|
50
|
+
quote.remove_symbols('MSFT', 'AAPL')
|
50
51
|
|
51
|
-
|
52
|
+
* To find data for all stocks, this will give a string containing all values:
|
52
53
|
|
53
|
-
|
54
|
+
quote.results.output
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
to return an array instead of a string use:
|
56
|
+
* To return an array instead of a string use:
|
58
57
|
|
59
58
|
quote.results(:to_array).output
|
60
|
-
|
61
|
-
|
62
|
-
|
59
|
+
|
60
|
+
* To return a hash, use:
|
61
|
+
|
63
62
|
quote.results(:to_hash).output
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
|
64
|
+
* To return xml, use:
|
65
|
+
|
67
66
|
quote.results(:to_xml).output
|
68
|
-
|
69
|
-
|
70
|
-
|
67
|
+
|
68
|
+
* to store results in a file, use:
|
69
|
+
|
71
70
|
quote.results.store('filename')
|
72
71
|
|
73
|
-
* To find out the stock symbol for a company
|
74
|
-
|
75
|
-
symbol = YahooStock::ScripSymbol.new('Yahoo')
|
72
|
+
* To find out the stock symbol for a company:
|
76
73
|
|
77
|
-
|
74
|
+
symbol = YahooStock::ScripSymbol.new('Yahoo')
|
78
75
|
|
79
|
-
|
76
|
+
* To find all symbols for that company, this will give a string containing all values:
|
80
77
|
|
81
|
-
|
78
|
+
symbol.results.output
|
79
|
+
|
80
|
+
* Similarly to YahooStock::Quote, results can be converted to an array, a hash, xml, or stored in a file:
|
82
81
|
|
83
82
|
symbol.results(:to_array).output
|
84
|
-
|
85
|
-
to return a hash, use:
|
86
|
-
|
87
83
|
symbol.results(:to_hash).output
|
88
|
-
|
89
|
-
to return xml, use:
|
90
|
-
|
91
|
-
quote.results(:to_xml).output
|
92
|
-
|
93
|
-
to store results in a file, use:
|
94
|
-
|
84
|
+
symbol.results(:to_xml).output
|
95
85
|
symbol.results.store('filename')
|
96
86
|
|
97
|
-
* To find symbols for multiple companies
|
87
|
+
* To find symbols for multiple companies:
|
98
88
|
|
99
|
-
symbols = YahooStock::ScripSymbol.results('Yahoo', 'Company1', 'Company3')
|
89
|
+
symbols = YahooStock::ScripSymbol.results('Yahoo', 'Company1', 'Company3')
|
100
90
|
|
101
|
-
*
|
91
|
+
* To find historical data for a stock:
|
102
92
|
|
103
|
-
|
93
|
+
history = YahooStock::History.new(:stock_symbol => 'yhoo', :start_date => Date.today-20, :end_date => Date.today -2)
|
104
94
|
|
105
|
-
*
|
106
|
-
|
107
|
-
symbols.store('filename')
|
108
|
-
|
109
|
-
* To find historical data for a stock
|
110
|
-
|
111
|
-
history = YahooStock::History.new(:stock_symbols => 'yhoo', :start_date => Date.today-20, end_date => Date.today -2)
|
112
|
-
|
113
|
-
to return an array instead of a string use:
|
95
|
+
* As with regular quotes and symbol lookups, the results can be returned in various formats:
|
114
96
|
|
97
|
+
history.results.output
|
115
98
|
history.results(:to_array).output
|
116
|
-
|
117
|
-
to return a hash, use:
|
118
|
-
|
119
|
-
to return xml, use:
|
120
|
-
|
121
|
-
quote.results(:to_xml).output
|
122
|
-
|
123
99
|
history.results(:to_hash).output
|
124
|
-
|
125
|
-
to store results in a file, use:
|
126
|
-
|
100
|
+
history.results(:to_xml).output
|
127
101
|
history.results.store('filename')
|
128
102
|
|
129
103
|
==Docs
|
@@ -132,9 +106,16 @@ http://rdoc.info/projects/nas/yahoo_stock
|
|
132
106
|
|
133
107
|
== TESTS:
|
134
108
|
|
135
|
-
|
109
|
+
To run all tests 'rspec spec' from the root directory. It requires rspec >= 2.1.0
|
110
|
+
|
111
|
+
To run cucumber features "rake cucumber". It requires cucumber >= 0.9.4
|
112
|
+
|
113
|
+
Cucumber Test html output is logged in log/features.html
|
114
|
+
|
115
|
+
==Thanks
|
116
|
+
|
117
|
+
* Thanks to {Ryan Sandridge}[http://github.com/dissolved] for adding the dividend query option.
|
136
118
|
|
137
|
-
To run all tests 'rake spec' from the root directory
|
138
119
|
|
139
120
|
== LICENSE:
|
140
121
|
|
data/Rakefile
CHANGED
@@ -1,22 +1,12 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
gem 'hoe', '>= 2.1.0'
|
3
|
-
require 'hoe'
|
4
|
-
require 'fileutils'
|
5
|
-
require './lib/yahoo_stock'
|
6
2
|
|
7
|
-
|
8
|
-
|
9
|
-
# Hoe.plugin :cucumberfeatures
|
3
|
+
require 'cucumber'
|
4
|
+
require 'cucumber/rake/task'
|
10
5
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
6
|
+
desc 'Run Cucumber features and generate an HTML summary'
|
7
|
+
Cucumber::Rake::Task.new(:cucumber) do |t|
|
8
|
+
t.cucumber_opts = ["--no-color",
|
9
|
+
"--format html -o log/features.html",
|
10
|
+
"--format progress"]
|
15
11
|
end
|
16
12
|
|
17
|
-
require 'newgem/tasks'
|
18
|
-
Dir['tasks/**/*.rake'].each { |t| load t }
|
19
|
-
|
20
|
-
# TODO - want other tests/tasks run by default? Add them to the list
|
21
|
-
# remove_task :default
|
22
|
-
# task :default => [:spec, :features]
|
@@ -28,7 +28,7 @@ module YahooStock
|
|
28
28
|
# :stock_symbol => 'goog', :start_date => Date.today-30,
|
29
29
|
# :end_date => Date.today-10, :interval => :weekly
|
30
30
|
#
|
31
|
-
# The interval option accepts :daily, :monthly and :
|
31
|
+
# The interval option accepts :daily, :monthly, :weekly and :dividend values
|
32
32
|
#
|
33
33
|
# The interval key is optional, if not used then by default uses :daily
|
34
34
|
#
|
@@ -83,9 +83,10 @@ module YahooStock
|
|
83
83
|
# Generate full uri with the help of uri method of the superclass
|
84
84
|
def uri
|
85
85
|
frequency = case interval
|
86
|
-
when :daily
|
87
|
-
when :weekly
|
88
|
-
when :monthly
|
86
|
+
when :daily then 'd'
|
87
|
+
when :weekly then 'w'
|
88
|
+
when :monthly then 'm'
|
89
|
+
when :dividend then 'v'
|
89
90
|
end
|
90
91
|
@uri_parameters = {:a => sprintf("%02d", start_date.month-1), :b => start_date.day,
|
91
92
|
:c => start_date.year, :d => sprintf("%02d", end_date.month-1),
|
@@ -109,7 +110,7 @@ module YahooStock
|
|
109
110
|
private
|
110
111
|
|
111
112
|
def validate_interval_values(interval_value=interval)
|
112
|
-
valid_values = [:daily, :weekly, :monthly]
|
113
|
+
valid_values = [:daily, :weekly, :monthly, :dividend]
|
113
114
|
unless valid_values.include?(interval_value)
|
114
115
|
raise HistoryError, "Allowed values for interval are #{valid_values.join(', ')}"
|
115
116
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -97,12 +97,12 @@ describe YahooStock::Interface::History do
|
|
97
97
|
:end_date => Date.today-1, :boom => 1) }.should raise_error(YahooStock::Interface::History::HistoryError, "An invalid key 'boom' is passed in the parameters. Allowed keys are stock_symbol, start_date, end_date, interval")
|
98
98
|
end
|
99
99
|
|
100
|
-
it "should raise error when interval is neither :daily, :weekly or :
|
100
|
+
it "should raise error when interval is neither :daily, :weekly, :monthly or :dividend" do
|
101
101
|
lambda { YahooStock::Interface::History.new(:stock_symbol => 'd',
|
102
102
|
:start_date => Date.today-7,
|
103
103
|
:end_date => Date.today-1,
|
104
104
|
:interval => :yearly)
|
105
|
-
}.should raise_error(YahooStock::Interface::History::HistoryError, "Allowed values for interval are daily, weekly, monthly")
|
105
|
+
}.should raise_error(YahooStock::Interface::History::HistoryError, "Allowed values for interval are daily, weekly, monthly, dividend")
|
106
106
|
|
107
107
|
end
|
108
108
|
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nas-yahoo_stock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 1
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
9
|
+
- 6
|
10
|
+
version: 1.0.6
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Nasir Jamal
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-11-13 00:00:00 +00:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: builder
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 15
|
27
30
|
segments:
|
28
31
|
- 2
|
29
32
|
- 1
|
@@ -57,6 +60,25 @@ files:
|
|
57
60
|
- lib/yahoo_stock/result/hash_format.rb
|
58
61
|
- lib/yahoo_stock/result/xml_format.rb
|
59
62
|
- lib/yahoo_stock/scrip_symbol.rb
|
63
|
+
- spec/spec_helper.rb
|
64
|
+
- spec/yahoo_stock/base_spec.rb
|
65
|
+
- spec/yahoo_stock/history_spec.rb
|
66
|
+
- spec/yahoo_stock/interface_spec.rb
|
67
|
+
- spec/yahoo_stock/interface/history_spec.rb
|
68
|
+
- spec/yahoo_stock/interface/quote_spec.rb
|
69
|
+
- spec/yahoo_stock/interface/scrip_symbol_spec.rb
|
70
|
+
- spec/yahoo_stock/quote_spec.rb
|
71
|
+
- spec/yahoo_stock/result_spec.rb
|
72
|
+
- spec/yahoo_stock/result/array_format_spec.rb
|
73
|
+
- spec/yahoo_stock/result/hash_format_spec.rb
|
74
|
+
- spec/yahoo_stock/result/xml_format_spec.rb
|
75
|
+
- spec/yahoo_stock/scrip_symbol_spec.rb
|
76
|
+
- features/history.feature
|
77
|
+
- features/quotes.feature
|
78
|
+
- features/script_symbol.feature
|
79
|
+
- features/step_definitions/history_steps.rb
|
80
|
+
- features/step_definitions/quotes_steps.rb
|
81
|
+
- features/step_definitions/script_symbol_steps.rb
|
60
82
|
has_rdoc: true
|
61
83
|
homepage: http://github.com/nas/yahoo_stock
|
62
84
|
licenses: []
|
@@ -67,24 +89,28 @@ rdoc_options:
|
|
67
89
|
require_paths:
|
68
90
|
- lib
|
69
91
|
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
70
93
|
requirements:
|
71
94
|
- - ">="
|
72
95
|
- !ruby/object:Gem::Version
|
96
|
+
hash: 31
|
73
97
|
segments:
|
74
98
|
- 1
|
75
99
|
- 8
|
76
100
|
version: "1.8"
|
77
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
78
103
|
requirements:
|
79
104
|
- - ">="
|
80
105
|
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
81
107
|
segments:
|
82
108
|
- 0
|
83
109
|
version: "0"
|
84
110
|
requirements: []
|
85
111
|
|
86
112
|
rubyforge_project:
|
87
|
-
rubygems_version: 1.3.
|
113
|
+
rubygems_version: 1.3.7
|
88
114
|
signing_key:
|
89
115
|
specification_version: 2
|
90
116
|
summary: Yahoo Stock is a Ruby library for extracting information about stocks from yahoo finance.
|