Class Finance::Quote
In: lib/finance/quote/yahoo/asia.rb
Parent: Object

This class implements financial quote operations.


Classes and Modules

Module Finance::Quote::AEX
Module Finance::Quote::Yahoo
Class Finance::Quote::QuoteData


cache  [RW] 
currency  [RW] 

Public Class methods

Returns a new Finance::Quote object, optionally setting the currency for future method calls. If currency is nil (the default), stock prices will be returned in the native currency of their exchange.

When cache is true and currency is not nil, exchange rates will be cached. This represents time savings of 90%.

Returns a list of registered plug-in modules.

This is used to register a plug-in module with Ruby/Finance. As such, this method is generally only useful if you are extending Ruby/Finance itself.

mod should be the name of the module to register, with methods being a Hash of exchange-to-method mappings.

For example:

 register_plugin( Finance::Quote::Yahoo::Australia,
                  { :australia => :yahoo_australia,
                    :yahoo_australia => :yahoo_australia } )

Used for scaling a field. This is useful, because it handles things like ranges, e.g. 105.4 - 108.3, not just set amounts.

The method takes a String or number to scale, and the factor by which to scale it. For example:

 scale_field( 1023, 0.01 )

This would return 10.23.

Public Instance methods

The hub of Ruby/Finance, this method is passed a market or exchange from which to retrieve pricing information about stocks. exchange may be a Symbol or a String, while stocks may be one or more Strings or an Array of Strings. Each String should represent a stock ticker symbol. A Finance::Quote::QuoteData object (basically a two-dimensional Hash will be returned.

In addition, this method may be passed a block. If this is done, the Finance::QuoteData will be yielded to the block. For example:

 q.fetch( :usa, 'AMZN' ) do |info|
   if info['AMZN'][:last].to_f < 5
     puts "Buy! Buy! Buy!"

It‘s also possible to directly call the method that maps to each exchange. For example, instead of calling fetch in the above example, ‘AMZN’ ) could have been used.