App-Chart
view release on metacpan or search on metacpan
lib/App/Chart/Yahoo.pm view on Meta::CPAN
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3, or (at your option) any later version.
#
# Chart is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with Chart. If not, see <http://www.gnu.org/licenses/>.
# Protocols:
#
# Don't know the full state of what Yahoo intends to offer.
# There's a range of "v1", "v7", "v8", "v11" URL forms.
# These might be meant as data sources for Yahoo client-side viewing.
# Don't think they're documented as such, but a few people have
# explored or put traces under the web site operation.
#
# The download forms might be only for logged-in Yahoo users.
# Would prefer not to require a Yahoo account for every user,
# esp since it's not as easy to do now as in the past.
# (But if that's a condition of use then would do so.)
#
# Here currently using
# v1 JSON for info (company name, exchange, decimals)
# v8 JSON for historical daily data
# v7 JSON for latest quote
#
# Each seem to be without protocol level hoops to jump through.
# Presumably all fall under the general Yahoo terms of service
# which think are personal use and no re-publication.
#
#
# Data Format:
#
# Each of these methods returns results in JSON format.
# The "download" URL form(s), as distinct from "chart", were/are CSV
# but might be restricted access now.
#
# JSON has prices put through single-precision floats,
# ie. 24 bit mantissa, which causes some price strings like
# 123.44999999 instead of 123.45.
#
# The parse here rounds that back to an apparent intended number
# of decimals (eg. 2 decimals for dollars and cents), but still
# allowing for trading in fractions of a cent as 3 or more decimals.
#
# In daily data, the current day's trading in progress shows at
# today's date and it changes though the course of trading.
# Don't know how or whether pre-market or post-market trading is
# applied, or what happens to a few futures or similar which might
# even be 24 hour trading.
#
# Dividends and splits seem to only appear on the ex date.
# That's disappointing since upcoming dividends often influence price
# action. (Which they shouldn't since everyone knows in advance.)
#
#
# Cookies and Crumb:
#
# In recent times there's been some protocol hoops to jump through.
# It seemed to be sometimes on the v7 download, maybe always on v11.
# The v7 JSON has been fine asking for the latest few days daily data,
# but not sure about bigger historical data.
#
# The hoops consisted of
#
# - Fetch one of the finance.yahoo.com web pages to get a
# HTTP Set-Cookie header.
# As of September 2024, there seems no such cookie any more
# (only a general user-tracking one for www.yahoo.com).
# - Maybe answer the ridiculous EU cookie consent on the page.
# Maybe that depends on where your IP seems to be from.
# (Not that an IP reliably indicates legal jurisdiction.)
# - Look deep within script in that page for a "crumb" string.
# Or maybe a further "getcrumb" web fetch, but seems result
# crumb is embedded in the page.
# - On each data download, HTTP Cookie header, and URL crumb
# field.
#
# Presumably this is designed either to track user activity, or
# as a level of difficulty to stop what Yahoo had said was
# widespread mis-use (contrary to personal use terms).
#
package App::Chart::Yahoo;
use 5.010;
use strict;
use warnings;
use Carp;
use Date::Calc;
use Date::Parse;
use JSON;
use List::Util qw (min max);
use POSIX ();
use Time::Local;
use URI::Escape;
use Locale::TextDomain ('App-Chart');
use Tie::TZ;
use App::Chart;
use App::Chart::Database;
use App::Chart::Download;
use App::Chart::DownloadHandler;
use App::Chart::DownloadHandler::IndivChunks;
use App::Chart::DownloadHandler::IndivInfo;
use App::Chart::IntradayHandler;
use App::Chart::Latest;
use App::Chart::Sympred;
use App::Chart::TZ;
use App::Chart::Weblink;
# uncomment this to run the ### lines
# use Smart::Comments;
# .X or .XY or no suffix
our $yahoo_pred = App::Chart::Sympred::Proc->new
(sub {
my ($symbol) = @_;
return ($symbol !~ /\.(FQ|LJ)$/
&& $symbol =~ /[.=]..?$|^[^.]+$/);
});
my $download_pred = App::Chart::Sympred::Any->new ($yahoo_pred);
our $latest_pred = App::Chart::Sympred::Any->new ($yahoo_pred);
our $index_pred = App::Chart::Sympred::Regexp->new (qr/^\^|^0.*\.SS$/);
my $futures_pred = App::Chart::Sympred::Any->new;
# overridden by specific nodes
App::Chart::setup_source_help
($yahoo_pred, __p('manual-node','Yahoo Finance'));
#-----------------------------------------------------------------------------
# Weblink - basic quote page
#
( run in 2.450 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )