App-Chart
view release on metacpan or search on metacpan
lib/App/Chart/Barchart.pm view on Meta::CPAN
'_{n} Days',
$n,
n => $n));
}
App::Chart::IntradayHandler->new
(pred => $intraday_pred,
proc => \&intraday_url,
mode => 'daily',
name => __('_Daily 2 Months'));
App::Chart::IntradayHandler->new
(pred => $intraday_pred,
proc => \&intraday_url,
mode => 'daily',
name => __('_Daily 1 Year'));
# 5 minute, linear scale
my %intraday_mode_to_data = ('1d' => '&p=I&d=L',
'2d' => '&p=I&d=O',
'3d' => '&p=I&d=M',
'4d' => '&p=I&d=H',
'5d' => '&p=I&d=X',
'daily2m' => '&p=DO&d=L',
'daily1y' => '&p=DO&d=X');
# '7d' => '&data=Z60&den=MEDHIGH',
# 'daily' => '&data=A');
sub intraday_url {
my ($self, $symbol, $mode) = @_;
App::Chart::Download::status
(__x('Barchart intraday page {symbol} {mode}',
symbol => $symbol,
mode => $mode));
my $url = 'http://www.barchart.com/chart.php?sym='
. URI::Escape::uri_escape (symbol_to_barchart ($symbol))
. $intraday_mode_to_data{$mode};
App::Chart::Download::verbose_message ("Intraday page", $url);
my $jar = cookie_jar();
my $resp = App::Chart::Download->get ($url,
cookie_jar => $jar,
referer => $url);
return (intraday_resp_to_url ($resp, $symbol),
cookie_jar => $jar,
referer => $url);
}
# separate func for offline testing ...
sub intraday_resp_to_url {
my ($resp, $symbol) = @_;
my $content = $resp->decoded_content (raise_error => 1);
require HTML::LinkExtor;
my $parser = HTML::LinkExtor->new(undef, $resp->base);
$parser->parse($content);
$parser->eof;
# eg.
# </map><img src="/cache/bde71ebe23ddac66f2d25081b1b5f953.png"
# must match some of the link target name since there's other images in
# the page
foreach my $link ($parser->links) {
my ($tag, %attr) = @$link;
$tag eq 'img' or next;
my $url = $attr{'src'};
index ($url, '/cache/') >= 0 or next;
### $url
return URI->new_abs($url,$resp->base)->as_string;
}
if ($content =~ /Could not find any symbols/i) {
die __x("No such symbol {symbol}\n",
symbol => $symbol);
} else {
die 'Barchart Customer: Intraday page not matched';
}
}
1;
__END__
# ---------------------------------------------------------------------------
# @node Barchart, Finance Quote, Data Sources, Data Sources
# @section Barchart
# @cindex @code{barchart.com}
#
# @uref{http://www.barchart.com}
#
# Barchart provides the following for various futures exchanges around the
# world,
#
# @itemize
# @c @item
# @c Quotes updated every 5 minutes, delayed according to the exchange.
# @c @item
# @c Intraday graphs.
# @item
# Historical data, but only for the past 5 days, and no volume figures.
# @item
# Historical data as graphs.
# @end itemize
#
# All information is for personal use only, see the terms at
#
# @quotation
# @uref{http://www2.barchart.com/agreement.asp} @*
# @uref{http://www2.barchart.com/ddfplus.asp}
# @end quotation
#
# In Chart symbols are the exchange commodity code and an exchange suffix as
# described below, with a month code letter and year, like @samp{CLZ10.NYM}
# for December 2010 crude oil.
# @c SYMBOL: CLZ10.NYM
#
# @c The commodity alone is the current front month, like
( run in 1.290 second using v1.01-cache-2.11-cpan-df04353d9ac )