App-Chart
view release on metacpan or search on metacpan
unused/Float.pm view on Meta::CPAN
#
# On a public holiday like http://www.float.com.au/download/20060414.zip
# the txt file is empty, or the zip file contains no files (no files at
# all, not even an empty txt file).
#
# Sometimes the server has got stuck or something, with no new data for a
# while. When that happens current days are empty files too. Give up after
# a few of those.
# return a url string like "http://www.float.com.au/download/20050909.zip"
sub daily_url {
my ($tdate) = @_;
my ($year, $month, $day) = App::Chart::tdate_to_ymd ($tdate);
return sprintf ('http://www.float.com.au/download/%04d%02d%02d.zip',
$year, $month, $day);
}
sub daily_download {
my ($lo, $hi) = @_;
my $empties = 0;
foreach my $tdate ($lo .. $hi) {
App::Chart::Download::status
(__x('Float.com.au data {date}',
date => App::Chart::Download::tdate_range_string ($tdate)));
my $url = daily_url($tdate);
my $resp = App::Chart::Download->get($url);
my $h = zip_parse ($url, $resp);
if ($h) {
$empties = 0;
$h->{'whole_day'} = '.AX';
$h->{'cost_key'} = 'float-wholeday-zip';
App::Chart::Download::write_daily_group ($h);
} else {
$empties++;
if ($empties >= 5) {
App::Chart::Download::download_message
(__x('Float too many empty days, giving up'));
last;
}
}
}
}
#-----------------------------------------------------------------------------
# download
#
# The download chooses between
# - float whole-day update files (possible zipped)
# - float individual historical files (possibly zipped)
#
# To update many ASX shares the whole-day files are best, or for just a few
# then the individual files are best. A mixture is used too, if there's a
# few symbols that are quite a bit behind then they'll be done
# individually, and the balance with whole-day.
#
# The main problem with the whole-day file is how many entries it has,
# about 4500 as of Jan 2007. There's about 1600 companies (a lot of them
# small caps), the rest is warrants on the majors, and a few prefs or bonds
# on various.
App::Chart::DownloadHandler->new
(name => __('Float'),
pred => $pred,
available_tdate => \&available_tdate,
proc => \&download,
priority => 20); # before 2nd commsec, and before yahoo
sub download {
my ($symbol_list) = @_;
App::Chart::Download::status (__('Float.com.au strategy'));
my $avail = available_tdate();
require App::Chart::DownloadCost;
my ($whole_tdate, @indiv_list) = App::Chart::DownloadCost::by_day_or_by_symbol
(available_tdate => $avail,
symbol_list => $symbol_list,
indiv_cost_key => 'float-indiv-zip',
indiv_cost_default => 30000, # depending when first listed
whole_cost_key => 'float-wholeday-zip',
whole_cost_default => 45000); # Sep 2007
App::Chart::Download::verbose_message
(__x('Float whole days from {date} after indiv {symbols}',
date => App::Chart::tdate_to_iso($whole_tdate),
symbols => join(' ', @indiv_list)));
foreach my $symbol (@indiv_list) { indiv_download ($symbol); }
daily_download ($whole_tdate, $avail);
}
1;
__END__
# ---------------------------------------------------------------------------
# Omitted while stuck at August 2008 ...
#
# @node Float, Finance Quote, Commonwealth Securities, Data Sources
# @section Float
# @cindex @code{float.com.au}
#
# @uref{http://www.float.com.au}
#
# @cindex Australian Stock Exchange
# @cindex ASX
# Float provides the following ASX data (@pxref{Australian Stock Exchange}),
#
# @itemize
# @item
# Daily data for shares, warrants and indices back to 1997. Each day's data is
# available from 9:15pm (Sydney time).
# @end itemize
#
# The home page invites use of the data download while the float database is
# being built, subject to a disclaimer at
#
# @quotation
( run in 0.767 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )