App-Chart

 view release on metacpan or  search on metacpan

lib/App/Chart/Suffix/BEN.pm  view on Meta::CPAN

    (name      => __('BSX stock numbers'),
     url       => 'http://www.bsx.com.au',
     key       => 'bendigo-codes',
     freq_days => 1,
     timezone  => $timezone_bendigo,
     parse     => \&secodes_parse);
  return $h->{$symbol};
}

# return hash reference { $symbol => $code, ... }
sub secodes_parse {
  my ($content) = @_;
  my %hash;
  while ($content =~ m{<option value=\"([0-9]+)\">([A-Z]+)</option>}g) {
    $hash{"$2.BEN"} = $1;
  }
  return \%hash;
}

1;
__END__

#------------------------------------------------------------------------------


# This uses the quotes pages like
#
#     http://www.bsx.com.au/markets_pricesresearch_pri.asp?security=20
#
# with the security code number from the symbols menu on the home page.
#
# www.bsx.com.au sends gzipped data, which is good since it compresses
# about 19kbytes of javascript junk down to about 3kbytes sent.
#
# The trade history pages like
#
#     http://www.bsx.com.au/markets_pricesresearch_tra.asp?security=1
#
# also have a current bid/offer and show the date/time of the last trade.
# Not sure if there's much value showing open/high/low/volume from trading
# that could be weeks ago.

# return list (ADATE TIME) for latest quote
#
# the BSX system takes changes only during 9:30am-11:30am weekdays (order
# entry 9:30 to 11, then trading 11 to 11:30), so outside those hours lock
# to 11:30am
#
# http://www.bsx.com.au/markets_aboutbsxmarkets_tra.asp
#
sub quote_date_time {
#   (tm->adate-time-within (localtime (current-time) (timezone-bendigo))
# 			 #,(hms->seconds 9 30 0)
# 			 #,(hms->seconds 11 30 0)))
}

sub bendigo_quote {

sub quote_parse {
  my ($resp) = @_;
  my $content = $resp->decoded_content (raise_error => 1);

  my @data = ();
  my $h = { source      => __PACKAGE__,
            resp        => $resp,
            date_format => 'dmy',
            data        => \@data };

  require HTML::TableExtract;

  my $te = HTML::TableExtract->new
    (headers   => ['code', 'bid', 'offer', 'last'],
     keep_html => 1);
  $te->parse($content);

  my ($ts) = $te->tables || die 'BSX: quote columns not found';
  $te = HTML::TableExtract->new
    (depth => $ts->depth,
     count => $ts->count + 1);
  $te->tables || die 'BSX: reparse table not found';

#   (receive-list (quote-adate quote-time)
#       (bendigo-quote-adate-time)

# 			# eg: <span class="Blue"><br><br><b>Capilano Honey Limited</b><br><font color=red>TRADING HALT</font><br></span><br>
# 			(m      (regexp-exec #,(regexp "Blue.*<b>.*red[^>]*>([^<]+)" regexp/icase regexp/newline) body))
# 			(note   (and m (match:substring m 1))))


  foreach my $row ($te->rows) {
    my ($code, $bid, $offer, $last) = @$row;
    $code =~ /(.*)\(([^)]+)\)/ or next;
    my $name   = $1;
    my $symbol = "$2.BEN";
    push @data, { symbol => $symbol,
                  name   => $name,
                  bid    => $bid,
                  offer  => $offer,
                  last   => $last };

			       #:quote-adate quote-adate
			       #:quote-time  quote-time
			       #:note        note
  }
}

(define (bendigo-latest-get symbol-list extra-list proc)
  (for-each (lambda (symbol)
	      (define option (symbol->option symbol))

	      (if (not option)
		  (proc (list (latest-new-unknown symbol)))

		  (receive (headers body)
		      (http-request (string-append "http://www.bsx.com.au/markets_pricesresearch_pri.asp?security=" option)
				    #:want-ok #t)
		    (proc (body->latest-list body)))))

	    symbol-list))

(latest-handler! #:selector   bendigo-symbol?  



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