Class: YahooStock::Quote
Overview
DESCRIPTION:
Provides the stock related current data.
Uses YahooStock::Interface to connect to yahoo and get relevant data.
USAGE:
-
Initialize quote object
quote = YahooStock::Quote.new(:stock_symbols => ['YHOO', 'GOOG'], :read_parameters => [:last_trade_price_only, :last_trade_date])
If read_parameters are not provided then by default the above two parameters are used.
-
To get data for all stocks
quote.get
-
To get data with real time values
quote.realtime
-
To get data with standard values
quote.standard
-
To get data with extra parameter values
quote.extended
-
To view the valid parameters that can be passed
quote.valid_parameters
-
To view the current parameters used
quote.current_parameters
-
To view the current stock symbols used
quote.current_symbols
-
To add more stocks to the list
quote.add_symbols('MSFT', 'AAPL')
-
To remove stocks from list
quote.remove_symbols('MSFT', 'AAPL')
Defined Under Namespace
Classes: QuoteException
Instance Method Summary collapse
-
#add_parameters(*parameters) ⇒ Object
Adds more parameters for the stock symbols to the existing instance for getting data.
-
#add_symbols(*symbols) ⇒ Object
Adds more stock symbols to the existing instance.
-
#clear_parameters ⇒ Object
Clear all existing parameters from the current instance.
-
#clear_symbols ⇒ Object
Clear all existing stock symbols from the current instance.
-
#current_parameters ⇒ Object
(also: #data_attributes)
Shows all parameters in the current instance that will be used to get results.
-
#current_symbols ⇒ Object
Show all stock symbols in the current instance that will be used to get results.
-
#initialize(options) ⇒ Quote
constructor
The options parameter expects a hash with two key value pairs.
-
#remove_parameters(*parameters) ⇒ Object
Removes parameters for the stock symbols to get values for from the existing instance.
-
#remove_symbols(*symbols) ⇒ Object
Removes stock symbols from the existing instance.
-
#use_all_parameters ⇒ Object
Set current instance to use all parameters to fetch values for current symbols.
-
#valid_parameters ⇒ Object
Returns an array of all allowed parameters that can be used.
Methods inherited from Base
Constructor Details
#initialize(options) ⇒ Quote
The options parameter expects a hash with two key value pairs
:stock_symbols => ‘Array of stock symbols’ or a single symbol
e.g. :stock_symbols => [‘MSFT’,‘YHOO’] or :stock_symbols => ‘YHOO’
another hash :read_parameters => ‘array of values’
e.g. :read_parameters => [:last_trade_price_only, :last_trade_date]
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/yahoo_stock/quote.rb', line 65 def initialize() if .nil? || !.is_a?(Hash) raise QuoteException, "You must provide a hash of stock symbols to fetch data" end if [:stock_symbols].nil? || [:stock_symbols].empty? raise QuoteException, "You must provide atleast one stock symbol to fetch data" end if !([:read_parameters] && [:read_parameters].any?) [:read_parameters] = [:last_trade_price_only, :last_trade_date] end [:stock_symbols] = Array.new << [:stock_symbols] unless [:stock_symbols].is_a?(Array) @interface = YahooStock::Interface::Quote.new() end |
Instance Method Details
#add_parameters(*parameters) ⇒ Object
Adds more parameters for the stock symbols to the existing instance for getting data. One or more parameters can be passed as argument.
117 118 119 |
# File 'lib/yahoo_stock/quote.rb', line 117 def add_parameters(*parameters) @interface.add_parameters(*parameters) end |
#add_symbols(*symbols) ⇒ Object
Adds more stock symbols to the existing instance. One or more stock symbols can be passed as parameter.
95 96 97 |
# File 'lib/yahoo_stock/quote.rb', line 95 def add_symbols(*symbols) @interface.add_symbols(*symbols) end |
#clear_parameters ⇒ Object
Clear all existing parameters from the current instance.
141 142 143 144 |
# File 'lib/yahoo_stock/quote.rb', line 141 def clear_parameters @interface.clear_parameters current_parameters end |
#clear_symbols ⇒ Object
Clear all existing stock symbols from the current instance.
106 107 108 |
# File 'lib/yahoo_stock/quote.rb', line 106 def clear_symbols @interface.clear_symbols end |
#current_parameters ⇒ Object Also known as: data_attributes
Shows all parameters in the current instance that will be used to get results.
128 129 130 |
# File 'lib/yahoo_stock/quote.rb', line 128 def current_parameters @interface.yahoo_url_parameters end |
#current_symbols ⇒ Object
Show all stock symbols in the current instance that will be used to get results.
111 112 113 |
# File 'lib/yahoo_stock/quote.rb', line 111 def current_symbols @interface.stock_symbols end |
#remove_parameters(*parameters) ⇒ Object
Removes parameters for the stock symbols to get values for from the existing instance. One of more parameters can be passed to remove.
123 124 125 |
# File 'lib/yahoo_stock/quote.rb', line 123 def remove_parameters(*parameters) @interface.remove_parameters(*parameters) end |
#remove_symbols(*symbols) ⇒ Object
Removes stock symbols from the existing instance. One of more stock symbols can be passed to remove.
101 102 103 |
# File 'lib/yahoo_stock/quote.rb', line 101 def remove_symbols(*symbols) @interface.remove_symbols(*symbols) end |
#use_all_parameters ⇒ Object
Set current instance to use all parameters to fetch values for current symbols.
135 136 137 138 |
# File 'lib/yahoo_stock/quote.rb', line 135 def use_all_parameters params = valid_parameters.each {|parameter| add_parameters(parameter)} sort_symbols(params) end |
#valid_parameters ⇒ Object
Returns an array of all allowed parameters that can be used.
147 148 149 |
# File 'lib/yahoo_stock/quote.rb', line 147 def valid_parameters sort_symbols(@interface.allowed_parameters) end |