YahooQuote(3pm)

๐Ÿ“ฆ version 0.25, in ubuntu jammy

๐ŸŽ€ 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 โ€” Symbol
  • 1 โ€” Company Name
  • 2 โ€” Last Price
  • 3 โ€” Last Trade Date
  • 4 โ€” Last Trade Time
  • 5 โ€” Change
  • 6 โ€” Percent Change
  • 7 โ€” Volume
  • 8 โ€” Average Daily Vol
  • 9 โ€” Bid
  • 10 โ€” Ask
  • 11 โ€” Previous Close
  • 12 โ€” Today's Open
  • 13 โ€” Day's Range
  • 14 โ€” 52-Week Range
  • 15 โ€” Earnings per Share
  • 16 โ€” P/E Ratio
  • 17 โ€” Dividend Pay Date
  • 18 โ€” Dividend per Share
  • 19 โ€” Dividend Yield
  • 20 โ€” Market Capitalization
  • 21 โ€” Stock Exchange

If the extended format has been selected, these fields get retrieved too:

  • 22 โ€” Short ratio
  • 23 โ€” 1yr Target Price
  • 24 โ€” EPS Est. Current Yr
  • 25 โ€” EPS Est. Next Year
  • 26 โ€” EPS Est. Next Quarter
  • 27 โ€” Price/EPS Est. Current Yr
  • 28 โ€” Price/EPS Est. Next Yr
  • 29 โ€” PEG Ratio
  • 30 โ€” Book Value
  • 31 โ€” Price/Book
  • 32 โ€” Price/Sales
  • 33 โ€” EBITDA
  • 34 โ€” 50-day Moving Avg
  • 35 โ€” 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 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