App-Chart
view release on metacpan or search on metacpan
lib/App/Chart/Barchart.pm view on Meta::CPAN
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
# @c @samp{GC.CMX} for gold, or
# @c @c SYMBOL: GC.CMX
#
# Barchart has some different commodity codes than the exchanges, but Chart
# always uses the exchange codes. Some Barchart pages show symbols with just
# one digit for the year, but Chart always uses two like @samp{10} above.
#
# Five days of historical data is very limited, but you can accumulate it to at
# least get a short term picture. Further data as graphs is available, and
# Chart has that as a ``Daily'' option in the intraday dialog
# (@pxref{Intraday}). (Further historical data as figures is available to
# subscribers, not currently supported by Chart.)
#
# For some of the exchanges below quotes are also available from Yahoo
# (@pxref{Yahoo Finance}). The download from Yahoo is much smaller and is hence
# preferred.
#
# @c @ifinfo
# @c @sp 1
# @c @end ifinfo
# @c @subsection Chicago Board of Trade
# @c @cindex Chicago Board of Trade
# @c @cindex CBOT
# @c
# @c @uref{http://www.cbot.com}
# @c
# @c @cindex @code{.CBOT}
# @c CBOT data is obtained from Barchart, and quotes from Yahoo (delayed 10
# @c minutes). In Chart symbols have a @samp{.CBOT} suffix, for example
# @c @samp{O.CBOT} for oats. Symbols (and trading hours) can be found at
# @c @c SYMBOL: O.CBOT
# @c
# @c @quotation
# @c @uref{http://www.cbot.com/cbot/pub/page/0@comma{}3181@comma{}932@comma{}00.html}
# @c @end quotation
# @c
# @c For some contracts Barchart has different symbols, but Chart always uses the
# @c exchange symbols.
# @c
( run in 0.744 second using v1.01-cache-2.11-cpan-39bf76dae61 )