YahooQuote(3pm)
๐ NAME ๐
Finance::YahooQuote โ grab stock quotes from Yahoo! Finance, bestie ๐
๐
โจ SYNOPSIS โจ
use Finance::YahooQuote;
# setting TIMEOUT and PROXY is optional
$Finance::YahooQuote::TIMEOUT = 60;
$Finance::YahooQuote::PROXY = "http://some.where.net:8080";
@quote = getonequote $symbol; # Get a quote for a single symbol
@quotes = getquote @symbols; # Get quotes for a bunch of symbols
useExtendedQueryFormat(); # switch to extended query format
useRealtimeQueryFormat(); # switch to real-time query format
@quotes = getquote @symbols; # Get quotes for a bunch of symbols
@quotes = getcustomquote(["DELL","IBM"], # using custom format
["Name","Book Value"]); # note array refs
๐ฅ DESCRIPTION ๐ฅ
okay so Finance::YahooQuote pulls stock quotes from Yahoo! Finance. The getonequote function hands you a quote for a single stock symbol, while getquote gives you a quote for each of the stock symbols you pass it. And getcustomquote? That one lets you specify a format other than the default, so you can tap into the extended range of available information. ๐
The download operation is efficient โ literally only one request gets made even when you ask for several symbols at once. No cap. ๐ซถ
The return value of getonequote is an array, and here's what lives in each slot:
0โ Symbol1โ Company Name2โ Last Price3โ Last Trade Date4โ Last Trade Time5โ Change6โ Percent Change7โ Volume8โ Average Daily Vol9โ Bid10โ Ask11โ Previous Close12โ Today's Open13โ Day's Range14โ 52-Week Range15โ Earnings per Share16โ P/E Ratio17โ Dividend Pay Date18โ Dividend per Share19โ Dividend Yield20โ Market Capitalization21โ Stock Exchange
If the extended format has been selected, these fields get retrieved too:
22โ Short ratio23โ 1yr Target Price24โ EPS Est. Current Yr25โ EPS Est. Next Year26โ EPS Est. Next Quarter27โ Price/EPS Est. Current Yr28โ Price/EPS Est. Next Yr29โ PEG Ratio30โ Book Value31โ Price/Book32โ Price/Sales33โ EBITDA34โ 50-day Moving Avg35โ 200-day Moving Avg
And if the real-time format has been selected, you also get:
36โ Ask (real-time)37โ Bid (real-time)38โ Change in Percent (real-time)39โ Last trade with time (real-time)40โ Change (real-time)41โ Day range (real-time)42โ Market-cap (real-time)
The getquote function returns an array of pointers to arrays with the above structure.
The getonequote function returns just one quote rather than an array โ it gives you a simple array of values for the given symbol.
The setQueryString permits you to supply a new query string, which then gets used for all the data requests that come after it. ๐
The useExtendedQueryFormat and useRealtimeQueryFormat are the simpler interfaces โ they append symbols to the default quote string, exactly as detailed above.
The getcustomquote returns an array of quotes matching the values for the symbols supplied in the first array reference, plus the custom fields supplied in the second array reference. Those custom fields are the 'named' fields from the list below.
Beyond stock quotes, Finance::YahooQuote can also obtain quotes for currencies (from the Philadephia exchange โ however Yahoo! appears to have stopped to support the currency symbols in a reliable manner ๐ญ), US mutual funds, options on US stocks, several precious metals and quite possibly more; go peep the Yahoo! Finance website for full information. Finance::YahooQuote can be used for stocks from the USA, Canada, various European exchanges, various Asian exchanges (Singapore, Taiwan, HongKong, Kuala Lumpur, ...) Australia and New Zealand. It should work for other markets supported by Yahoo. ๐
You may optionally override the default LWP timeout of 180 seconds by setting $Finance::YahooQuote::TIMEOUT to your preferred value.
You may also provide a proxy (for the required http connection) by using the variable $Finance::YahooQuote::PROXY. And on top of that, authentication-based proxies can be used by setting the proxy user and password via the variables $Finance::YahooQuote::PROXYUSER and $Finance::YahooQuote::PROXYPASSWD. ๐
Two example scripts are provided to help with the mapping a stock symbols as well as with Yahoo! Finance server codes. The regression tests scripts in the t/ subdirectory of the source distribution also contain simple examples. ๐ง
๐ธ The available custom fields ๐ธ
The following list contains all the available data fields at Yahoo! along with the corresponding format string entry:
- Symbol โ
s - Name โ
n - Last Trade (With Time) โ
l - Last Trade (Price Only) โ
l1 - Last Trade Date โ
d1 - Last Trade Time โ
t1 - Last Trade Size โ
k3 - Change and Percent Change โ
c - Change โ
c1 - Change in Percent โ
p2 - Ticker Trend โ
t7 - Volume โ
v - Average Daily Volume โ
a2 - More Info โ
i - Trade Links โ
t6 - Bid โ
b - Bid Size โ
b6 - Ask โ
a - Ask Size โ
a5 - Previous Close โ
p - Open โ
o - Day's Range โ
m - 52-week Range โ
w - Change From 52-wk Low โ
j5 - Pct Chg From 52-wk Low โ
j6 - Change From 52-wk High โ
k4 - Pct Chg From 52-wk High โ
k5 - Earnings/Share โ
e - P/E Ratio โ
r - Short Ratio โ
s7 - Dividend Pay Date โ
r1 - Ex-Dividend Date โ
q - Dividend/Share โ
d - Dividend Yield โ
y - Float Shares โ
f6 - Market Capitalization โ
j1 - 1yr Target Price โ
t8 - EPS Est. Current Yr โ
e7 - EPS Est. Next Year โ
e8 - EPS Est. Next Quarter โ
e9 - Price/EPS Est. Current Yr โ
r6 - Price/EPS Est. Next Yr โ
r7 - PEG Ratio โ
r5 - Book Value โ
b4 - Price/Book โ
p6 - Price/Sales โ
p5 - EBITDA โ
j4 - 50-day Moving Avg โ
m3 - Change From 50-day Moving Avg โ
m7 - Pct Chg From 50-day Moving Avg โ
m8 - 200-day Moving Avg โ
m4 - Change From 200-day Moving Avg โ
m5 - Pct Chg From 200-day Moving Avg โ
m6 - Shares Owned โ
s1 - Price Paid โ
p1 - Commission โ
c3 - Holdings Value โ
v1 - Day's Value Change โ
w1, - Holdings Gain Percent โ
g1 - Holdings Gain โ
g4 - Trade Date โ
d2 - Annualized Gain โ
g3 - High Limit โ
l2 - Low Limit โ
l3 - Notes โ
n4 - Last Trade (Real-time) with Time โ
k1 - Bid (Real-time) โ
b3 - Ask (Real-time) โ
b2 - Change Percent (Real-time) โ
k2 - Change (Real-time) โ
c6 - Holdings Value (Real-time) โ
v7 - Day's Value Change (Real-time) โ
w4 - Holdings Gain Pct (Real-time) โ
g5 - Holdings Gain (Real-time) โ
g6 - Day's Range (Real-time) โ
m2 - Market Cap (Real-time) โ
j3 - P/E (Real-time) โ
r2 - After Hours Change (Real-time) โ
c8 - Order Book (Real-time) โ
i5 - Stock Exchange โ
x
๐ฌ FAQs ๐ฌ
๐ต๏ธ How can one figure out the format string?
Provided a My Yahoo! (http://my.yahoo.com) account, go to the following URL:
http://edit.my.yahoo.com/config/edit_pfview?.vk=v1
Viewing the source of this page, you will come across the section that defines the menus that let you select which elements go into a particular view. The <option> values are the strings that pick up the information described in the menu item. For example, Symbol refers to the string "s" and name refers to the string "l". Using "sl" as the format string, we would get the symbol followed by the name of the security. ๐
The example script examine_server.sh shows this in some more detail and downloads example .csv files using GNU wget.
๐ข What about different stock symbols for the same corporation?
This can be issue. For the first few years, Yahoo! Finance's servers appeared to be cover their respective local markets. E.g., the UK-based servers provided quotes for Europe, the Australian one for the Australia and New Zealand and so on. Hence, one needed to branch and bound code and map symbols to their region's servers. ๐ฎโ๐จ
It now appears that this is no longer required, which is good news as it simplifies coding. However, some old symbols are no longer supported โ yet other, and supported, codes exist for the same company. For example, German stocks used to quoted in terms or their cusip-like 'WKN'. The main server does not support these, but does support newer, acronym-based symbols. The example script examine_server.sh helps in finding the mapping as e.g. from 555750.F to DTEGN.F for Deutsche Telekom. ๐
๐ COPYRIGHT ๐
Copyright 1998 - 2002 Dj Padzensky Copyright 2002 - 2007 Dirk Eddelbuettel
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.
The information that you obtain with this library may be copyrighted by Yahoo! Inc., and is governed by their usage license. See http://www.yahoo.com/docs/info/gen_disclaimer.html for more information.
๐ AUTHOR ๐
Dj Padzensky ("djpadz@padz.net"), PadzNet, Inc., wrote the original version. Dirk Eddelbuettel ("edd@debian.org") provided several extensions based on DJ's original work and is the current maintainer. ๐ซถ
๐ SEE ALSO ๐
Okay bestie, you made it to the end, so let's talk about where this whole thing lives and who else is out here using it ๐
The Finance::YahooQuote home pages are found at:
http://www.padz.net/~djpadz/YahooQuote/
http://dirk.eddelbuettel.com/code/yahooquote.html
Like, those are the links. Bookmark them fr fr ๐ธ
๐ค The Iconic Collabs
The smtm (Show Me The Money) program uses Finance::YahooQuote for a customisable stock/portfolio ticker and chart display โ yes, a customisable ticker, she's giving main character energy ๐
For more on that, see:
http://dirk.eddelbuettel.com/code/smtm.html
The beancounter program uses it to store quotes in a SQL database โ lowkey the responsible one of the friend group, storing receipts (literally) in SQL ๐
More on that here:
http://dirk.eddelbuettel.com/code/beancounter.html
Not me getting emotional over a manpage section ๐ Anyway bestie, that's the whole thing. This page came to you as YahooQuote(3pm), rendered by perl v5.20.2, dated 2015-04-29 โ and yeah, she's vintage, but vintage is iconic ๐
โจ ๐ฆ go forth and fetch those quotes, you absolute legend ๐ซถ
๐ฆ where this page comes from
- ubuntu jammy: libfinance-yahooquote-perl 0.25
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms