they-yahoo_stock 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/History.txt +98 -0
  2. data/Manifest.txt +37 -0
  3. data/README.rdoc +151 -0
  4. data/Rakefile +12 -0
  5. data/features/history.feature +23 -0
  6. data/features/quotes.feature +23 -0
  7. data/features/script_symbol.feature +23 -0
  8. data/features/step_definitions/history_steps.rb +44 -0
  9. data/features/step_definitions/quotes_steps.rb +45 -0
  10. data/features/step_definitions/script_symbol_steps.rb +40 -0
  11. data/lib/yahoo_stock.rb +21 -0
  12. data/lib/yahoo_stock/base.rb +37 -0
  13. data/lib/yahoo_stock/history.rb +32 -0
  14. data/lib/yahoo_stock/interface.rb +71 -0
  15. data/lib/yahoo_stock/interface/history.rb +187 -0
  16. data/lib/yahoo_stock/interface/quote.rb +287 -0
  17. data/lib/yahoo_stock/interface/scrip_symbol.rb +74 -0
  18. data/lib/yahoo_stock/quote.rb +158 -0
  19. data/lib/yahoo_stock/result.rb +21 -0
  20. data/lib/yahoo_stock/result/array_format.rb +23 -0
  21. data/lib/yahoo_stock/result/hash_format.rb +37 -0
  22. data/lib/yahoo_stock/result/xml_format.rb +37 -0
  23. data/lib/yahoo_stock/scrip_symbol.rb +61 -0
  24. data/spec/spec_helper.rb +4 -0
  25. data/spec/yahoo_stock/base_spec.rb +48 -0
  26. data/spec/yahoo_stock/history_spec.rb +75 -0
  27. data/spec/yahoo_stock/interface/history_spec.rb +317 -0
  28. data/spec/yahoo_stock/interface/quote_spec.rb +414 -0
  29. data/spec/yahoo_stock/interface/scrip_symbol_spec.rb +120 -0
  30. data/spec/yahoo_stock/interface_spec.rb +112 -0
  31. data/spec/yahoo_stock/quote_spec.rb +258 -0
  32. data/spec/yahoo_stock/result/array_format_spec.rb +14 -0
  33. data/spec/yahoo_stock/result/hash_format_spec.rb +65 -0
  34. data/spec/yahoo_stock/result/xml_format_spec.rb +54 -0
  35. data/spec/yahoo_stock/result_spec.rb +33 -0
  36. data/spec/yahoo_stock/scrip_symbol_spec.rb +46 -0
  37. metadata +114 -0
@@ -0,0 +1,98 @@
1
+ === 0.1.1 2009-08-31
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
5
+
6
+ === 0.1.2 2009-09-01
7
+
8
+ * 1 minor change:
9
+ * changed method name YahooStock::Quote#get_data to get
10
+
11
+ === 0.1.3 2009-09-05
12
+
13
+ * 3 additions:
14
+ * adds a new class called YahooStock::ScripSymbol that allows to
15
+ find out the stock symbol for a company
16
+ * adds specs for previous and new code
17
+ * adds
18
+
19
+ === 0.1.4 2009-09-05
20
+
21
+ * 2 changes related with ruby 1.9:
22
+ * modifies quote class to be compatible with ruby 1.9
23
+ * modifies interface class to be compatible with 1.9
24
+
25
+ === 0.1.5 2009-09-06
26
+
27
+ * 1 changes related with ruby 1.9:
28
+ * modifies ScripSymbol class to be compatible with ruby 1.9
29
+
30
+ === 0.1.6 2009-09-07
31
+
32
+ * 1 addition:
33
+ * adds convenience methods Quote#realtime, standard and extended to
34
+ fetch relevant stock values
35
+
36
+ === 1.0.1 2009-09-10
37
+
38
+ * 1 addition:
39
+ * adds feature to retrieve historical stock data
40
+
41
+ === 1.0.2 2009-10-04
42
+ Major changes in the public API. Check the README.rdoc file and individual classes for more information
43
+
44
+ * 8 addition:
45
+ * adds YahooStock::Interface::History
46
+ * adds YahooStock::Interface::Quote
47
+ * adds YahooStock::Interface::ScripSymbol
48
+ * adds YahooStock::Result as a superclass for all formatter classes
49
+ * adds array format, Result::ArrayFormat, to generate results as an array
50
+ * adds hash format, Result::ArrayFormat, to generate results as key value pairs
51
+ * adds base class as parent for public facing classes
52
+ * adds observers to check when it is required to send request to yahoo again to get fresh data
53
+
54
+ * 7 changes:
55
+ * changes YahooStock::Interface to be the main interface class. Other interface classes will inherit from this
56
+ * changes YahooStock::ScripSymbol to use YahooStock::Interface::ScripSymbol
57
+ * removes all history interface logic from YahooStock::History and uses YahooStock::Interface::History
58
+ * changes YahooStock::Quote, YahooStock::History, YahooStock::ScripSymbol to extend from YahooStock::Base
59
+ * sorts url parameters before sending request to yahoo
60
+ * YahooInterface::Quote#realtime, extended, and standard methods should return self to allow calling different format output method calls
61
+ * do not discard any empty values when finding scrip symbol options for a company as this interferes with different format options
62
+
63
+ === 1.0.3 2009-10-04
64
+
65
+ * 2 changes:
66
+ * changes README file to add reference for gemcutter
67
+ * changes gemspec to use nas-yahoo_stock
68
+
69
+ === 1.0.4 2009-10-23
70
+
71
+ * 2 addition:
72
+ * adds support for xml format
73
+ * adds cucumber features
74
+
75
+ * 1 changes:
76
+ * changes README file to remove git source add for github
77
+
78
+ === 1.0.5 2010-05-07
79
+
80
+ * 1 change:
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
91
+
92
+ === 1.0.7 2010-11-14
93
+
94
+ * Some refactoring after the addition of dividend option to the history
95
+
96
+ === 1.0.8 2011-05-25
97
+
98
+ * Parse csv data correctly using CSV gem instead to reinventing the wheel
@@ -0,0 +1,37 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ lib/yahoo_stock/base.rb
6
+ lib/yahoo_stock/history.rb
7
+ lib/yahoo_stock/interface.rb
8
+ lib/yahoo_stock/interface/history.rb
9
+ lib/yahoo_stock/interface/quote.rb
10
+ lib/yahoo_stock/interface/scrip_symbol.rb
11
+ lib/yahoo_stock/quote.rb
12
+ lib/yahoo_stock/result.rb
13
+ lib/yahoo_stock/result/array_format.rb
14
+ lib/yahoo_stock/result/hash_format.rb
15
+ lib/yahoo_stock/result/xml_format.rb
16
+ lib/yahoo_stock/scrip_symbol.rb
17
+ lib/yahoo_stock.rb
18
+ spec/spec_helper.rb
19
+ spec/yahoo_stock/base_spec.rb
20
+ spec/yahoo_stock/interface_spec.rb
21
+ spec/yahoo_stock/interface/history_spec.rb
22
+ spec/yahoo_stock/interface/quote_spec.rb
23
+ spec/yahoo_stock/interface/scrip_symbol_spec.rb
24
+ spec/yahoo_stock/quote_spec.rb
25
+ spec/yahoo_stock/history_spec.rb
26
+ spec/yahoo_stock/result_spec.rb
27
+ spec/yahoo_stock/result/array_format_spec.rb
28
+ spec/yahoo_stock/result/hash_format_spec.rb
29
+ spec/yahoo_stock/result/xml_format_spec.rb
30
+ spec/yahoo_stock/scrip_symbol_spec.rb
31
+ features/history.feature
32
+ features/quotes.feature
33
+ features/script_symbol.feature
34
+ features/step_definitions/history_steps.rb
35
+ features/step_definitions/quotes_steps.rb
36
+ features/step_definitions/script_symbol_steps.rb
37
+
@@ -0,0 +1,151 @@
1
+ = yahoo_stock
2
+
3
+ * http://github.com/nas/yahoo_stock
4
+
5
+ == DESCRIPTION:
6
+
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
+
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
+ YahooStock::Quote object and passing valid_parameters message to the quote object, example is given below in the USAGE section.
12
+
13
+ For details : http://nasir.wordpress.com/2009/10/28/ruby-gem-for-finance-data
14
+
15
+
16
+ == INSTALL:
17
+
18
+ gem sources -a http://gemcutter.org
19
+
20
+ sudo gem install nas-yahoo_stock
21
+
22
+
23
+ == USAGE:
24
+
25
+ require 'rubygems'
26
+ require 'yahoo_stock'
27
+
28
+ * Initialize quote object:
29
+
30
+ quote = YahooStock::Quote.new(:stock_symbols => ['YHOO', 'GOOG'])
31
+
32
+ * To view the valid parameters that can be passed:
33
+
34
+ quote.valid_parameters
35
+
36
+ * To view the current parameters used:
37
+
38
+ quote.current_parameters
39
+
40
+ * To view the current stock symbols used:
41
+
42
+ quote.current_symbols
43
+
44
+ * To add more stocks to the list:
45
+
46
+ quote.add_symbols('MSFT', 'AAPL')
47
+
48
+ * To remove stocks from list:
49
+
50
+ quote.remove_symbols('MSFT', 'AAPL')
51
+
52
+ * To find data for all stocks, this will give a string containing all values:
53
+
54
+ quote.results.output
55
+
56
+ * To return an array instead of a string use:
57
+
58
+ quote.results(:to_array).output
59
+
60
+ * To return a hash, use:
61
+
62
+ quote.results(:to_hash).output
63
+
64
+ * To return xml, use:
65
+
66
+ quote.results(:to_xml).output
67
+
68
+ * to store results in a file, use:
69
+
70
+ quote.results.store('filename')
71
+
72
+ * To find out the stock symbol for a company:
73
+
74
+ symbol = YahooStock::ScripSymbol.new('Yahoo')
75
+
76
+ * To find all symbols for that company, this will give a string containing all values:
77
+
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:
81
+
82
+ symbol.results(:to_array).output
83
+ symbol.results(:to_hash).output
84
+ symbol.results(:to_xml).output
85
+ symbol.results.store('filename')
86
+
87
+ * To find symbols for multiple companies:
88
+
89
+ symbols = YahooStock::ScripSymbol.results('Yahoo', 'Company1', 'Company3')
90
+
91
+ * To find historical data for a stock:
92
+
93
+ history = YahooStock::History.new(:stock_symbol => 'yhoo', :start_date => Date.today-20, :end_date => Date.today-2)
94
+
95
+ * As with regular quotes and symbol lookups, the results can be returned in various formats:
96
+
97
+ history.results.output
98
+ history.results(:to_array).output
99
+ history.results(:to_hash).output
100
+ history.results(:to_xml).output
101
+ history.results.store('filename')
102
+
103
+ * History results include 7 values for each day, i.e. date itself, Open, High, Low, Close, Volume and Adj.
104
+
105
+ * To get comma separated values with line breaks including header use:
106
+
107
+ history.values_with_header
108
+ (writing this to a file will give a CSV)
109
+
110
+ ==Docs
111
+
112
+ http://rdoc.info/projects/nas/yahoo_stock
113
+
114
+ == TESTS:
115
+
116
+ To run all tests 'rspec spec' from the root directory. It requires rspec >= 2.1.0
117
+
118
+ To run cucumber features "rake cucumber". It requires cucumber >= 0.9.4
119
+
120
+ Cucumber Test html output is logged in log/features.html
121
+
122
+ ==Thanks
123
+
124
+ * Thanks to {Ryan Sandridge}[http://github.com/dissolved] for adding the dividend query option.
125
+ * Thanks to {Justin Campbell} [https://github.com/JustinCampbell] for refactoring CSV parsing.
126
+
127
+
128
+ == LICENSE:
129
+
130
+ (The MIT License)
131
+
132
+ Copyright (c) 2009 Nasir Jamal
133
+
134
+ Permission is hereby granted, free of charge, to any person obtaining
135
+ a copy of this software and associated documentation files (the
136
+ 'Software'), to deal in the Software without restriction, including
137
+ without limitation the rights to use, copy, modify, merge, publish,
138
+ distribute, sublicense, and/or sell copies of the Software, and to
139
+ permit persons to whom the Software is furnished to do so, subject to
140
+ the following conditions:
141
+
142
+ The above copyright notice and this permission notice shall be
143
+ included in all copies or substantial portions of the Software.
144
+
145
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
146
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
147
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
148
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
149
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
150
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
151
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+
3
+ require 'cucumber'
4
+ require 'cucumber/rake/task'
5
+
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"]
11
+ end
12
+
@@ -0,0 +1,23 @@
1
+ Feature: Find historical stock data for a stock
2
+ As a user
3
+ I want to find historical data for a stock
4
+ So that I can use the historical data
5
+ Scenario: Get historical data
6
+ Given I do not have any historical data for the symbol "msft"
7
+ When I get historical data for "msft"
8
+ Then I should be able to get history results as a comma separated values in a string
9
+
10
+ Scenario: Get results in array format
11
+ Given I have the history results for the symbol "yhoo"
12
+ When I want to get the history results in array format
13
+ Then I should get an array of history values
14
+
15
+ Scenario: Get results in hash format
16
+ Given I have the history results for the symbol "yhoo"
17
+ When I want to get the history results in hash format
18
+ Then I should get an array of hash key values for history
19
+
20
+ Scenario: Get results in xml format
21
+ Given I have the history results for the symbol "yhoo"
22
+ When I want to get the history results in xml format
23
+ Then I should be able to get history result as xml
@@ -0,0 +1,23 @@
1
+ Feature: Get quotes for a stock
2
+ As a user
3
+ I want to get the stock quotes
4
+ So that I can use them in different formats
5
+ Scenario: Get stock quotes
6
+ Given I do not have any quote results
7
+ When I want to get the quotes for the symbol "yhoo"
8
+ Then I should be able to get results as a comma separated values in a string
9
+
10
+ Scenario: Get results in array format
11
+ Given I have the results for the symbol "yhoo"
12
+ When I want to get the results in array format
13
+ Then I should get an array of values
14
+
15
+ Scenario: Get results in hash format
16
+ Given I have the results for the symbol "yhoo"
17
+ When I want to get the results in hash format
18
+ Then I should get an array of hash key values
19
+
20
+ Scenario: Get results in xml format
21
+ Given I have the results for the symbol "yhoo"
22
+ When I want to get the results in xml format
23
+ Then I should be able to get result as xml
@@ -0,0 +1,23 @@
1
+ Feature: Find Script Symbols
2
+ As a user
3
+ I want to find the script symbols for a company
4
+ So that I can use in other classes
5
+ Scenario: Find Scrip Symbols
6
+ Given I know the name of the company "Yahoo"
7
+ When I try to find the scrip symbols for "Yahoo"
8
+ Then I should be able to get scrip symbol results as a comma separated values in a string
9
+
10
+ Scenario: Get symbol results in array format
11
+ Given I have the scrip symbol results for the symbol "yhoo"
12
+ When I want to get the scrip symbol results in array format
13
+ Then I should get an array of values for scrip symbol
14
+
15
+ Scenario: Get symbol results in hash format
16
+ Given I have the scrip symbol results for the symbol "yhoo"
17
+ When I want to get the scrip symbol results in hash format
18
+ Then I should get an array of hash key values for scrip symbol
19
+
20
+ Scenario: Get symbol results in xml format
21
+ Given I have the scrip symbol results for the symbol "yhoo"
22
+ When I want to get the scrip symbol results in xml format
23
+ Then I should be able to get scrip symbol result as xml
@@ -0,0 +1,44 @@
1
+ Given /^I do not have any historical data for the symbol "([^\"]*)"$/ do |scrip_symbol|
2
+ @history = nil
3
+ end
4
+
5
+ When /^I get historical data for "([^\"]*)"$/ do |arg1|
6
+ @history = YahooStock::History.new(:stock_symbol => 'msft',
7
+ :start_date => Date.today-10,
8
+ :end_date => Date.today-2)
9
+ @results = @history.results
10
+ end
11
+
12
+ Then /^I should be able to get history results as a comma separated values in a string$/ do
13
+ @results.output.should =~ /.*,.*/
14
+ end
15
+
16
+ Given /^I have the history results for the symbol "([^\"]*)"$/ do |stock_symbol|
17
+ @history_format = YahooStock::History.new(:stock_symbol => stock_symbol,
18
+ :start_date => Date.today-4,
19
+ :end_date => Date.today-2)
20
+ end
21
+
22
+ When /^I want to get the history results in array format$/ do
23
+ @array_output = @history_format.results(:to_array).output
24
+ end
25
+
26
+ Then /^I should get an array of history values$/ do
27
+ @array_output.should_not be_empty
28
+ end
29
+
30
+ When /^I want to get the history results in hash format$/ do
31
+ @hash_output = @history_format.results(:to_hash).output
32
+ end
33
+
34
+ Then /^I should get an array of hash key values for history$/ do
35
+ @hash_output.first.keys.should_not be_nil
36
+ end
37
+
38
+ When /^I want to get the history results in xml format$/ do
39
+ @xml_output = @history_format.results(:to_xml).output
40
+ end
41
+
42
+ Then /^I should be able to get history result as xml$/ do
43
+ @xml_output.should =~ /^\<xml*/
44
+ end
@@ -0,0 +1,45 @@
1
+ Given /^I do not have any quote results$/ do
2
+ @quote = nil
3
+ end
4
+
5
+ When /^I want to get the quotes for the symbol "([^\"]*)"$/ do |stock_symbol|
6
+ @quote = YahooStock::Quote.new(:stock_symbols => stock_symbol)
7
+ @results = @quote.results
8
+ end
9
+
10
+ Then /^I should be able to get results as a comma separated values in a string$/ do
11
+ @results.output.should =~ /.*,.*/
12
+ end
13
+
14
+ Given /^I have the results for the symbol "([^\"]*)"$/ do |stock_symbol|
15
+ @quote_format = YahooStock::Quote.new(:stock_symbols => stock_symbol)
16
+ end
17
+
18
+ When /^I want to get the results in array format$/ do
19
+ @array_output = @quote_format.results(:to_array).output
20
+ end
21
+
22
+ Then /^I should get an array of values$/ do
23
+ @array_output.should_not be_empty
24
+ end
25
+
26
+ Then /^by default there should only be two values$/ do
27
+ @array_output.size.should eql(2)
28
+ end
29
+
30
+ When /^I want to get the results in hash format$/ do
31
+ @hash_output = @quote_format.results(:to_hash).output
32
+ end
33
+
34
+ Then /^I should get an array of hash key values$/ do
35
+ @hash_output.first.keys.should include(:last_trade_price_only, :last_trade_date)
36
+ end
37
+
38
+ When /^I want to get the results in xml format$/ do
39
+ @xml_output = @quote_format.results(:to_xml).output
40
+ end
41
+
42
+ Then /^I should be able to get result as xml$/ do
43
+ @xml_output.should =~ /^\<xml*/
44
+ end
45
+