App-Chart

 view release on metacpan or  search on metacpan

unused/TradingRoom.pm  view on Meta::CPAN

# the full year, with no compression offered apparently.
#
App::Chart::DownloadHandler->new
  (name            => __('TradingRoom'),
   pred            => App::Chart::Sympred::Regexp->new (qr/^.{4,}\.AX$/),
   available_tdate => \&available_tdate,
   proc            => \&download,
   priority        => 10);

# today's data available ...
sub available_tdate {
  App::Chart::Download::tdate_today_after
      (23,59, App::Chart::TZ->sydney);
}

sub download {
  my ($symbol_list) = @_;
  foreach my $symbol (@$symbol_list) {
    indiv_download ($symbol);
  }
}

#------------------------------------------------------------------------------
# download - by each symbol
#
# This uses the CSV 1-year download.  Eg. symbol like NABHA
#
#     http://www.tradingroom.com.au/apps/qt/csv/pricehistory.ac?section=yearly_price_download&code=NABHA

sub indiv_download {
  my @symbol_list = @_;

  foreach my $symbol (@symbol_list) {
    my $url = 'http://www.tradingroom.com.au/apps/qt/csv/pricehistory.ac?section=yearly_price_download&code='
      . URI::Escape::uri_escape (App::Chart::symbol_sans_suffix($symbol));

    App::Chart::Download::status (__x('TradingRoom {symbol} 1-year',
                                      symbol => $symbol));

    my $resp = App::Chart::Download->get($url);
    my $h = indiv_parse ($resp, $symbol);
    if ($h) {
      $h->{'last_download'} = 1;
      App::Chart::Download::write_daily_group ($h);
    }
  }
}

# $symbol like "NABHA.AX"
sub indiv_parse {
  my ($resp, $symbol) = @_;
  my @data = ();
  my $h = { source          => __PACKAGE__,
            currency        => 'AUD',
            suffix          => '.AX',
            prefer_decimals => 2,
            date_format     => 'dmy',
            resp            => $resp,
            data            => \@data };

  my $body = $resp->decoded_content(raise_error=>1);

  # Like
  #
  #     Date,Open,High,Low,Close,Volume,Cumulative Dilution Factor
  #     25-Jun-2015,94.6100,94.9000,94.5900,94.8000,7581,1
  #
  # 4 decimals so can be fractions of a cent.
  # Unknown symbol is heading but no data lines.
  # 
  my @lines = App::Chart::Download::split_lines($body);
  {
    my $heading = shift @lines;
    $heading =~ /^Date,Open,High,Low,Close,Volume(,|$)/i
      or die 'TradingRoom: unrecognised heading line: ',$heading;
  }
    
  foreach my $line (@lines) {
    my ($date, $open, $high, $low, $close, $volume)
      = split (/,/, $line);

    push @data, { symbol => $symbol,
                  date   => $date,
                  open   => $open,
                  high   => $high,
                  low    => $low,
                  close  => $close,
                  volume => $volume };
  }
  return $h;
}

1;
__END__







# use App::Chart::TradingRoom;

# @c ---------------------------------------------------------------------------
# @node Trading Room, Yahoo Finance, Thrift Savings Plan, Data Sources
# @section Trading Room
# @cindex @code{tradingroom.com.au}
# 
# @uref{tradingroom.com.au}
# 
# @cindex Australian Stock Exchange
# @cindex ASX
# Trading Room is used for the following Australian Stock Exchange data,
# 
# @itemize
# @item
# Preference shares daily data for past 1 year.
# @end itemize
# 
# Each day's data is available some time overnight of the same day.  Chart will
# attempt from midnight onwards (Sydney time).



( run in 1.003 second using v1.01-cache-2.11-cpan-437f7b0c052 )