Ruby/Finance allows access to changing financial data, such as currency conversion rates and stock quotes. It is a partial port of Perl Finance::Quote module, currently implementing the Yahoo Finance modules and the Amsterdam Euronext eXchange (AEX) module.
Please note that the AEX module is currently obsolete, due to the removal of the underlying service that it used.
Please see the INSTALL file supplied with the software for details of how to install Ruby/Finance. It‘s very simple and involves running just a single script.
require 'finance/currency' # Display the US Dollar ($) to Euro (¤) conversion rate. # puts Finance::Currency::convert( 'EUR', 'USD' ) # Display the British Pounds Sterling (£) to Icelandic Kronur conversion # rate for the amount of £32.50. # puts Finance::Currency::convert( 'ISK', 'GBP', 32.50 )
require 'finance/quote' q = Finance::Quote.new # Answers will be given in the native # currency of the exchange on which # they are listed. q = Finance::Quote.new( 'EUR' ) # Answers will be given in Euros. q.currency = 'VND' # Switch to using Vietnamese Dong. info = q.fetch( 'usa', 'CRM' ) # Fetch a single quote, namely CRM. info = q.fetch( :usa, 'EBAY', 'AMZN' ) # Fetch EBAY and AMZN. Note that # a Symbol can be used instead of a # String for the exchange name. info = q.fetch( 'usa', %w[ EBAY AMZN ] ) # An Array of ticker symbols is # OK, too. puts info['EBAY'][:price] # A block can be passed, too: # q.fetch( :usa, 'RHAT' ) { |info| puts info['RHAT'][:high] } # You can also bypass #fetch and call the exchange as a method: q.usa( 'RHAT' ) { |info| puts info['RHAT'][:high] }
The Finance::Quote#fetch method accepts an exchange (either a Symbol or a String), followed by a list of one or more stocks to fetch. This list may be a variable length list of Strings or an Array of Strings. It returns an object of class QuoteData, which is basically a two-dimensional Hash. The outer index is the stock ticker symbol, which can be referenced as either a Symbol (e.g. :RHAT) or a String (e.g. ‘RHAT‘). Internally, however, it is a String. The inner index is referred to as the label and must be referenced as a Symbol. In the above examples, you can see labels such as :price and :high in use.
When information about a stock is returned, the following labels are filled with data:
The first argument passed to the Finance::Quote#fetch method is the exchange to query. The following exchanges are currently recognised:
More exchanges will be added in the fullness of time.
Ruby/Finance is a Ruby port of Perl‘s Finance::Quote module.
The contributors to Finance::Quote at the time of porting (v1.08) were:
DJ Padzensky <djpadz@padz.net> Linas Vepstas <linas@linas.org> Yannick LE NY <y-le-ny@ifrance.com> Paul Fenwick <pjf@cpan.org> Brent Neal <brentn@users.sourceforge.net>
Finance::Quote itself started life as the Quote module, which was distributed as part of GnuCash. That module was a modified version of Finance::YahooQuote, which was written by DJ Padzensky. At that point, it was separated from GnuCash and became an independent project.
Since that time, many people have contributed to Finance::Quote, including Xose Manoel Ramos (inheritable Yahoo! methods), Brent Neal, Keith Refson, and Volker Stuerzl (pluggable modules), and Peter Thatcher, Jacinta Richardson and Steven Murdoch (who contributed various bug-fixes and improvements).
Author: | Ian Macdonald <ian@caliban.org> |
Version: | 0.2.3 |
Licence: | GPL |
Returns an array of [ host, port, user, password ], based on the setting of $http_proxy. Each of these will be nil if the corresponding data element is not set.
This method is likely to be of little use to you, as it is primarily intended for the internal use of Ruby/Finance.