App-Chart
view release on metacpan or search on metacpan
unused/YahooOld.pm view on Meta::CPAN
my ($symbol, $resp, $h, $hi_tdate) = @_;
my @data = ();
$h->{'data'} = \@data;
my $hi_tdate_iso;
if (defined $hi_tdate){ $hi_tdate_iso = App::Chart::tdate_to_iso($hi_tdate); }
my $body = $resp->decoded_content (raise_error => 1);
my @line_list = App::Chart::Download::split_lines($body);
unless ($line_list[0] =~ /^Date,Open,High,Low,Close,Adj Close,Volume/) {
die "Yahoo: unrecognised daily data headings: " . $line_list[0];
}
shift @line_list;
foreach my $line (@line_list) {
my ($date, $open, $high, $low, $close, $adj_volume, $volume)
= split (/,/, $line);
$date = daily_date_fixup ($symbol, $date);
if (defined $hi_tdate_iso && $date gt $hi_tdate_iso) {
# Sep 2017: There's a daily data record during the trading day, but
# want to write the database only at the end of trading.
### skip date after hi_tdate ...
next;
}
# Sep 2017 have seen "null,null,null,...", maybe for non-trading days
foreach my $field ($open, $high, $low, $close, $adj_volume, $volume) {
if ($field eq 'null') {
$field = undef;
}
}
if ($index_pred->match($symbol)) {
# In the past indexes which not calculated intraday had
# open==high==low==close and volume==0, eg. ^WIL5. Use the close
# alone in this case, with the effect of drawing line segments instead
# of OHLC or Candle figures with no range.
if (defined $open && defined $high && defined $low && defined $close
&& $open == $high && $high == $low && $low == $close && $volume == 0){
$open = undef;
$high = undef;
$low = undef;
}
} else {
# In the past shares with no trades had volume==0,
# open==low==close==bid price, and high==offer price, from some time
# during the day, maybe the end of day. Zap all the prices in this
# case.
#
# For a public holiday it might be good to zap the volume to undef
# too, but don't have anything to distinguish holiday, suspension,
# delisting vs just no trades.
#
# On the ASX when shares are suspended the bid/offer can be crossed as
# usual for pre-open auction, and this gives high<low. For a part-day
# suspension then can have volume!=0 in this case too. Don't want to
# show a high<low, so massage high/low to open/close range if the high
# looks like a crossed offer.
if (defined $high && defined $low && $high < $low) {
$high = App::Chart::max_maybe ($open, $close);
$low = App::Chart::min_maybe ($open, $close);
}
if (defined $open && defined $low && defined $close && defined $volume
&& $open == $low && $low == $close && $volume == 0) {
$open = undef;
$high = undef;
$low = undef;
$close = undef;
}
}
push @data, { symbol => $symbol,
date => $date,
open => crunch_trailing_nines($open),
high => crunch_trailing_nines($high),
low => crunch_trailing_nines($low),
close => crunch_trailing_nines($close),
volume => $volume };
}
return $h;
}
sub daily_parse_div {
my ($symbol, $resp, $h) = @_;
my @dividends = ();
$h->{'dividends'} = \@dividends;
my $body = $resp->decoded_content (raise_error => 1);
my @line_list = App::Chart::Download::split_lines($body);
# Date,Dividends
# 2015-11-04,1.4143
# 2016-05-17,1.41428
# 2017-05-16,1.4143
# 2016-11-03,1.4143
unless ($line_list[0] =~ /^Date,Dividends/) {
warn "Yahoo: unrecognised dividend headings: " . $line_list[0];
return;
}
shift @line_list;
foreach my $line (@line_list) {
my ($date, $amount) = split (/,/, $line);
push @dividends, { symbol => $symbol,
ex_date => daily_date_fixup ($symbol, $date),
amount => $amount };
}
return $h;
}
sub daily_parse_split {
my ($symbol, $resp, $h) = @_;
my @splits = ();
$h->{'splits'} = \@splits;
my $body = $resp->decoded_content (raise_error => 1);
( run in 0.614 second using v1.01-cache-2.11-cpan-5a3173703d6 )