Finance::Quote(3)
π NAME π
Finance::Quote β get stock and mutual fund quotes from various exchanges. Yes bestie, it's literally fetching financial data from all over the internet and handing it back to you π
β¨ SYNOPSIS β¨
use Finance::Quote;
$q = Finance::Quote->new;
%quotes = $q->fetch("nasdaq", @stocks);
π DESCRIPTION π
This module gets stock quotes from various internet sources all over the world. Quotes are obtained by constructing a quoter object and using the fetch method to gather data, which is returned as a two-dimensional hash (or a reference to such a hash, if called in a scalar context). It's giving "financial data main character energy" fr fr.
For example:
$q = Finance::Quote->new;
%info = $q->fetch("australia", "CML");
print "The price of CML is ".$info{"CML", "price"};
The first part of the hash (eg, "CML") is referred to as the stock. The second part (in this case, "price") is referred to as the label. Keep that distinction in your head, bestie β it comes up again π«Ά
πΈ LABELS πΈ
When information about a stock is returned, the following standard labels may be used. Some custom-written modules may use labels not mentioned here. If you wish to be certain that you obtain a certain set of labels for a given stock, you can specify that using require_labels().
askβ Askavg_volβ Average Daily Volbidβ Bidcapβ Market Capitalizationcloseβ Previous Closecurrencyβ Currency code for the returned datadateβ Last Trade Date (MM/DD/YYformat)day_rangeβ Day's Rangedivβ Dividend per Sharediv_dateβ Dividend Pay Datediv_yieldβ Dividend Yieldepsβ Earnings per Shareerrormsgβ If success is false, this field may contain the reason why.ex_divβ Ex-Dividend Date.exchangeβ The exchange the information was obtained from.highβ Highest trade todayisinβ International Securities Identification Numberisodateβ ISO 8601 formatted datelastβ Last Pricelowβ Lowest trade todaymethodβ The module (as could be passed to fetch) which found this information.nameβ Company or Mutual Fund Namenavβ Net Asset Valuenetβ Net Changeopenβ Today's Openp_changeβ Percent Change from previous day's closepeβ P/E Ratiosuccessβ Did the stock successfully return information? (true/false)timeβ Last Trade Timetypeβ The type of equity returnedvolumeβ Volumeyear_rangeβ 52-Week Rangeyieldβ Yield (usually 30 day avg)
If all stock lookups fail (possibly because of a failed connection) then the empty list may be returned, or undef in a scalar context. Not the vibe, but at least it's documented π
π INSTALLATION π
Please note that the Github repository is not meant for general users of Finance::Quote for installation. Read that again, bestie β the GitHub repo is not the install spot for regular users π«Ά
If you downloaded the Finance-Quote-N.NN.tar.gz tarball from CPAN (N.NN is the version number, ex: Finance-Quote-1.50.tar.gz), run the following commands:
tar xzf Finance-Quote-1.50.tar.gz
cd Finance-Quote-1.50.tar.gz
perl Makefile.PL
make
make test
make install
bestie, yes, thecdline in the original saysFinance-Quote-1.50.tar.gzβ copy it exactly as shown, I don't make the rules π
If you have the CPAN module installed: Using cpanm (Requires App::cpanminus)
cpanm Finance::Quote
or Using CPAN shell
perl -MCPAN -e shell
install Finance::Quote
π«Ά SUPPORT AND DOCUMENTATION π«Ά
After installing, you can find documentation for this module with the perldoc command.
perldoc Finance::Quote
You can also look for information at:
- Finance::Quote GitHub project β https://github.com/finance-quote/finance-quote
- Search CPAN β http://search.cpan.org/dist/Finance-Quote
- The Finance::Quote home page β http://finance-quote.sourceforge.net/
- The Finance::YahooQuote home page β http://www.padz.net/~djpadz/YahooQuote/
- The GnuCash home page β http://www.gnucash.org/
π PUBLIC CLASS METHODS π
Finance::Quote implements public class methods for constructing a quoter object, getting or setting default class values, and for listing available methods. Class methods are the backstage crew, but make it iconic β¨
β¨ new β¨
my $q = Finance::Quote->new()
my $q = Finance::Quote->new('-defaults')
my $q = Finance::Quote->new(timeout => 30)
my $q = Finance::Quote->new('YahooJSON', fetch_currency => 'EUR')
my $q = Finance::Quote->new('alphavantage' => {API_KEY => '...'})
my $q = Finance::Quote->new(currency_rates => {order => ['ECB', 'Fixer'], 'fixer' => {API_KEY => '...'}});
Finance::Quote modules access a wide range of sources to provide quotes. A module provides one or more methods to fetch quotes. One method is usually the name of the module in lower case. Other methods, if provided, are descriptive names, such as 'canada', 'nasdaq', or 'nyse'.
A Finance::Quote object uses one or more methods to fetch quotes for securities.
new constructs a Finance::Quote object and enables the caller to load only specific modules, set parameters that control the behavior of the fetch method, and pass method specific parameters.
timeout => Tβ sets the web request timeout toTsecondsfailover => Bβ whereBis a boolean value indicating if failover in fetch is permittedfetch_currency => Cβ sets the desired currency code toCfor fetch resultscurrency_rates => Hβ configures the order currency rate modules are consulted for exchange rates and currency rate module optionsrequired_labels => Aβ sets the required labels for fetch results to arrayAModuleNameas a string β the name of a specificFinance::Quote::Moduleto loadmethodname => Hβ passes hashHtomethodnameduring fetch to configure the method
With no arguments, new creates a Finance::Quote object with the default methods. If the environment variable FQ_LOAD_QUOTELET is set, then the contents of FQ_LOAD_QUOTELET (split on whitespace) will be used as the argument list. This allows users to load their own custom modules without having to change existing code. If any method names are passed to new or the flag '-defaults' is included in the argument list, then FQ_LOAD_QUOTELET is ignored. So don't set it and then get confused, bestie π
When new() is passed one or more class name arguments, an object is created with only the specified modules loaded. If the first argument is '-defaults', then the default modules will be loaded first, followed by any other specified modules. Note that the FQ_LOAD_QUOTELET environment variable must begin with '-defaults' if you wish the default modules to be loaded.
Method names correspond to the Perl module in the Finance::Quote module space. For example, Finance::Quote->new('ASX') will load the module Finance::Quote::ASX, which provides the method asx.
Some methods require API keys or have unique options. Passing 'method => HASH' to new() enables the caller to provide a configuration HASH to the corresponding method.
The key 'currency_rates' configures the Finanace::Quote currency rate conversion. By default, to maintain backward compatibility, Finance::Quote::CurrencyRates::AlphaVantage is used for currency conversion. This end point requires an API key, which can either be set in the environment or included in the configuration hash. To specify a different primary currency conversion method or configure fallback methods, include the 'order' key, which points to an array of Finance::Quote::CurrencyRates module names. Setting the environment variable FQ_CURRENCY will change the default endpoint used for currency conversion. See the documentation for the individual Finance::Quote::CurrencyRates modules to learn more.
π get_default_currency_fields π
my @fields = Finance::Quote::get_default_currency_fields();
get_default_currency_fields returns the standard list of fields in a quote that are automatically converted during currency conversion. Individual modules may override this list. It's the default squad, but some modules have main character energy and do their own thing π
β° get_default_timeout β°
my $value = Finance::Quote::get_default_timeout();
get_default_timeout returns the current Finance::Quote default timeout in seconds for web requests. Finance::Quote does not specify a default timeout, deferring to the underlying user agent for web requests. So this function will return undef unless set_default_timeout was previously called. No timeout by default β chaotic but documented π«
β³ set_default_timeout β³
Finance::Quote::set_default_timeout(45);
set_default_timeout sets the Finance::Quote default timeout to a new value.
π get_methods π
my @methods = Finance::Quote::get_methods();
get_methods returns the list of methods that can be passed to new when creating a quoter object and as the first argument to fetch.
π get_features π
my %features = Finance::Quote::get_features();
get_features returns a hash with three keys: quote_methods, quote_modules, and currency_modules.
$features{quote_methods} is a hash with key/value pairs of method_name => [array of module names]
$features{quote_modules} is a hash with key/value pairs of module_name => [array of parameter names]
$features{currency_modules} is a hash with key/value pairs of currency_module_name => [array of paramater names]
Parameter names are values that the module needs to function, such as API_KEY. Most modules will have an empty list. Modules with a parameter are configured when creating the Finance::Quote by passing the argument
'module_name_in_lower_case' => {paramter => value}
to Finance::Quote->new().
The keys of the $features{currency_modules} hash are the names of currency modules that can be used for currency conversion and the order in which the modules are used is controlled by the argument
currency_rates => {order => [subset of $features{currency_modules}]}
to Finance::Quote->new(). By default, AlphaVantage is used for currency conversion, "order" can be set to use other currency modules. The currency module used can also be changed by setting the FQ_CURRENCY environment variable. Please note that some of the alternate currency modules require API keys.
π PUBLIC OBJECT METHODS
okay bestie, these ones you call on your quoter object $q β the little guy you built earlier. each one's a whole vibe, let's go π«Ά
B_to_billionsβ this utility function takes a numeric string with aBsuffix and expands it to the corresponding multiple of1000000000. so like:
my $value = $q->B_to_billions("20B");
it's giving "20 billion, but as a real number" β¨
decimal_shiftupβ moves that decimal point in a numeric string to the right by however many places you tell it. iconic for scaling things up π₯
my $value = $q->decimal_shiftup("123.45", 1); # returns 1234.5
my $value = $q->decimal_shiftup("0.25", 1); # returns 2.5
fetchβ the main character, honestly. it takes a method as its first argument, and everything after that is treated as securities:
my %stocks = $q->fetch("alphavantage", "IBM", "MSFT", "LNUX");
my $hashref = $q->fetch("nasdaq", "IBM", "MSFT", "LNUX");
important note: if your quoter $q was constructed with a specific method (or methods), then only those methods are available to you. no sneaking in extras π
call it in an array context and you get a hash back. call it in a scalar context and you get a reference to a hash. either way, the keys of the returned hash are "{SECURITY,LABEL}". so with the example above, $stocks{"IBM","high"} is the high value for IBM. slay.
and if you're ever like "wait, what methods even are there?" β $q->get_methods() returns the list of valid methods for quoter object $q. some methods point at one specific Finance::Quote module, like 'alphavantage'. others are available from multiple Finance::Quote modules, like 'nasdaq'. the quoter failover option is what decides whether multiple modules get consulted for methods such as 'nasdaq' that have more than one implementation π
get_failoverβ returns a boolean telling you whether your quoter object will use failover or not.
my $failover = $q->get_failover();
and what is failover? it's when fetch tries to grab quote info for a security from alternate sources if the requested method flops. lowkey a safety net πΈ
set_failoverβ flips the failover flag on the quoter object.
$q->set_failover(False);
get_fetch_currencyβ returns the desired currency code for the quoter object, orundefif no target currency was set during construction or with theset_fetch_currencyfunction.
my $currency = $q->get_fetch_currency();
set_fetch_currencyβ this one asks for all your info to come back in a specified currency. adorable, right? but listen:
$q->set_fetch_currency("FRF"); # Get results in French Francs.
heads up bestie π¨ setting a fetch currency increases the chance of stock-lookup failure, because remote requests have to be made to fetch both the stock information and the currency rates. to improve reliability and speed performance, currency conversion rates are cached and are assumed not to change for the duration of the Finance::Quote object.
see the introduction to this page for how to configure the source of currency conversion rates π§
get_required_labelsβ returns the list of labels that must be populated for a security quote to be considered valid and returned byfetch.
my @labels = $q->get_required_labels();
set_required_labelsβ updates the list of required labels for the quoter object.
my $labels = ['close', 'isodate', 'last'];
$q->set_required_labels($labels);
get_timeoutβ returns the timeout in seconds that the quoter object uses for web requests.
my $timeout = $q->get_timeout();
set_timeoutβ updates that timeout in seconds for the quoter object. 45 seconds of patience, periodt β³
$q->set_timeout(45);
store_dateβ used by modules to consistently store date information about securities. you hand it the various pieces of a date, and it figures out how to construct an ISO date (yyyy-mm-dd) and a US date (mm/dd/yyyy) and stores those values in%infofor security$stock. it's giving "one date, two formats, zero stress" π
$quoter->store_date(\%info, $stocks, {eurodate => '06/11/2020'});
get_user_agentβ returns theLWP::UserAgentthe quoter object is using for web requests.
my $ua = $q->get_user_agent();
isoTimeβ returns an ISO formatted time. literally just glow-up your clock β
$q->isoTime("11:39PM"); # returns "23:39"
$q->isoTime("9:10 AM"); # returns "09:10"
π PUBLIC CLASS OR OBJECT METHODS
these next ones are available as class methods, but you can also call them from Finance::Quote objects. dual threat, honestly π
scale_fieldβ a utility function that scales the first argument by the second argument. in the example below,valueis'10.23':
my $value = Finance::Quote->scale_field('1023', '0.01')
currencyβ converts a value with a currency code suffix into another currency, using the current exchange rate as determined by theFinance::Quote::CurrencyRatesmethod (or methods) configured for the quoter$q.
my $value = $q->currency('15.95 USD', 'AUD');
my $value = Finance::Quote->currency('23.45 EUR', 'RUB');
when called as a class method,Finance::Quote::AlphaVantageis the default β and that one requires an API key π see the introduction for info on configuring currency rate conversions, and seeFinance::Quote::CurrencyRates::AlphaVantagefor the deets on that API key.
currency_lookupβ takes zero or more constraints and filters the list of currencies known to Finance::Quote. returns a hash reference where the keys are ISO currency codes and the values are hash references containing metadata about the currency. so many options, so much flair β¨
my $currency = $quoter->currency_lookup();
my $currency = $quoter->currency_lookup( name => "Caribbean");
my $currency = $quoter->currency_loopup( country => qw/denmark/i );
my $currency = $q->currency_lookup(country => qr/united states/i, number => 840);
a constraint is a key name plus either a scalar or a regular expression. a currency satisfies the constraint if its metadata hash contains the constraint key and the value of that metadata field matches the regular expression, or contains the constraint value as a substring. and if the metadata field is an array, then it satisfies the constraint if any value in the array satisfies it. equal opportunity filtering π
parse_csvβ utility function for splitting a comma separated value string into a list of terms, treating double-quoted strings that contain commas as a single value. those sneaky embedded commas don't stand a chance π
my @list = Finance::Quote::parse_csv($string);
parse_csv_semicolonβ same energy, but for semicolon separated value strings: splits them into a list of terms, treating double-quoted strings that contain semicolons as a single value.
my @list = Finance::Quote::parse_csv_semicolon($string);
π¦ LEGACY METHODS
these are the old ones that got a glow-up. still here, still listed, but they've been replaced β pls use the new names bestie π
default_currency_fieldsβ replaced withget_default_currency_fields().sourcesβ replaced withget_methods().failoverβ replaced withget_failover()andset_failover().require_labelsβ replaced withget_required_labels()andset_required_labels().user_agentβ replaced withget_user_agent().set_currencyβ replaced withget_fetch_currency()andset_fetch_currency().
πΈ ENVIRONMENT
Finance::Quote respects all the environment that your installed version of LWP::UserAgent respects. most importantly, it respects the http_proxy environment variable β so if your setup lives behind a proxy, it's got you π«Ά
π USAGE COUNTER
a simple usage counter has been enabled. bestie, before you panic: other than the user's IP address, Finance::Quote version, and which method was used, no other data is collected. none. zilch.
wanna opt out of your usage being counted? just set the environment variable FQ_NOCOUNT and you're invisible π
π BUGS
- the caller cannot control the fetch failover order. not a vibe, but it's the truth.
- the two-dimensional hash is a somewhat unwieldly method of passing around information when compared to references. we said what we said π
π COPYRIGHT & LICENSE
Copyright 1998, Dj Padzensky
Copyright 1998, 1999 Linas Vepstas
Copyright 2000, Yannick LE NY (update for Yahoo Europe and YahooQuote)
Copyright 2000-2001, Paul Fenwick (updates for ASX, maintenance and release)
Copyright 2000-2001, Brent Neal (update for TIAA-CREF)
Copyright 2000 Volker Stuerzl (DWS)
Copyright 2001 Rob Sessink (AEX support)
Copyright 2001 Leigh Wedding (ASX updates)
Copyright 2001 James Treacy (TD Waterhouse support)
Copyright 2008 Erik Colson (isoTime)
this program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. iconic of it honestly π
currency information fetched through this module is bound by the terms and conditons of the data source.
other copyrights and conditions may apply to data fetched through this module. please refer to the sub-modules for further information.
π§ AUTHORS
the following list are those contributors with 5 or more commits in the GitHub repository. please see the Git log for all the authors who have helped with Finance::Quote β the whole group chat, truly π«Ά
Erik Colson <eco@ecocode.net>
Bruce Schuck <bschuck@asgard-systems.com>
Paul Fenwick <pjf@perltraining.com.au>
Vincent Lucarelli <vincent.lucarelli@gmail.com>
David Hampton <hampton-sf@rainbolthampton.net>
jvolkening <jdv@base2bio.com>
Pawel Konieczny <konieczp@zonnet.nl>
Mike Alexander <mta@umich.edu>
AndreJ <Andre-J@users.noreply.github.com>
Vinay S Shastry <vinayshastry@gmail.com>
Bradley Dean <bjdean@bjdean.id.au>
Brent Neal <brent@reindeergraphics.com>
Jacinta Richardson <jarich@perltraining.com.au>
e-dorigatti <emilio.dorigatti@gmail.com>
goodvibes2 <goodchris96@gmail.com>
Paul Howarth <paul@city-fan.org>
Sam Morris <sam@robots.org.uk>
Linas Vepstas <linas@linas.org>
Rajan Vaswani <111571283+bgr22112@users.noreply.github.com>
Hiranya Samarasekera <hiranyas@gmail.com>
Manuel Friedli <manuel@fritteli.ch>
the Finance::Quote home page can be found at http://finance-quote.sourceforge.net/
the Finance::YahooQuote home page can be found at http://www.padz.net/~djpadz/YahooQuote/
the GnuCash home page can be found at http://www.gnucash.org/
π SEE ALSO π
Bestie, these are the related pages youβll want to pull up next β same friend group, different lore:
Finance::Quote::CurrencyRates::AlphaVantageFinance::Quote::CurrencyRates::CurrencyFreaksFinance::Quote::CurrencyRates::ECBFinance::Quote::CurrencyRates::FinanceAPIFinance::Quote::CurrencyRates::FixerFinance::Quote::CurrencyRates::FrankfurterFinance::Quote::CurrencyRates::OpenExchangeFinance::Quote::CurrencyRates::TwelveDataFinance::Quote::CurrencyRates::UniRateFinance::Quote::CurrencyRates::YahooJSONFinance::Quote::ASEGRFinance::Quote::ASXFinance::Quote::BorsaItalianaFinance::Quote::BSEIndiaFinance::Quote::BoursoFinance::Quote::BVBFinance::Quote::CSEFinance::Quote::ComdirectFinance::Quote::ConsorsbankFinance::Quote::CurrenciesFinance::Quote::DekaFinance::Quote::FinanceAPIFinance::Quote::FinanzpartnerFinance::Quote::FinnhubFinance::Quote::FondswebFinance::Quote::FoolFinance::Quote::FTfundsFinance::Quote::GoldMoneyFinance::Quote::GoogleWebFinance::Quote::IndiaMutualFinance::Quote::MarketWatchFinance::Quote::MorningstarJPFinance::Quote::NPSNAVFinance::Quote::NSEIndiaFinance::Quote::NZXFinance::Quote::OnVistaFinance::Quote::SIXFinance::Quote::StockDataFinance::Quote::StooqFinance::Quote::SwissFundDataFinance::Quote::TSPFinance::Quote::TMXFinance::Quote::TesouroDiretoFinance::Quote::TreasuryDirectFinance::Quote::TwelveDataFinance::Quote::UnionFinance::Quote::USBondsFinance::Quote::YahooJSONFinance::Quote::YahooWebFinance::Quote::XETRAFinance::Quote::ZA
You should have received the Finance::Quote hackerβs guide with this package. Please read it if youβre interested in adding extra methods to this package. The latest hackerβs guide can also be found on GitHub at https://github.com/finance-quote/finance-quote/blob/master/Documentation/Hackers-Guide β go get your read on, bestie π
π DONATIONS π
Okay so the contributors to Finance::Quote are genuinely happy to volunteer their time and resources, but donations are helpful and a great way to say thank you. So far the only real cost to the team is domain registration for finance-quote.org. However, some operating systems and hardware upgrades do have a cost. Access to the latest or current environments is needed for development and testing. Upgrades to the latest MS Windows often includes a cost, and recently Appleβs move to ARM/M1/M2 CPUs has stifled some contributorsβ ability to assist. π
With that in mind, you can send donations to the email address donations@finance-quote.org through PayPal. If itβs for a particular contributor, please indicate in a note while submitting the donation through PayPal.
Additionally, Bitcoin donations can be received at 37Bg4EMAp575j4iL9jHv1ZhDgiropU38jY.
This page is from perl v5.32.1, dated 2026-10-26, and itβs Finance::Quote(3) β mwah, bye bestie πβ¨
π¦ where this page comes from
- epel 9: perl-Finance-Quote 1.7200-1.el9 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms