package Finance::TW::EmergingQuote;
our $VERSION = '0.26';
use strict;
use LWP::Simple ();
use Encode 'from_to';
sub resolve {
die "not implemented";
}
sub new {
my ($class, $target) = @_;
my $self = bless {}, $class;
$self->resolve($target)
unless $target =~ /^\d+$/;
$self->{id} ||= $target;
return $self;
}
sub get {
my $self = shift if ref($_[0]) eq __PACKAGE__;
shift if $_[0] eq __PACKAGE__;
my $stockno = $self ? $self->{id} : shift;
my $content = LWP::Simple::get("http://nweb.otc.org.tw/main.htm");
from_to($content, 'big5', 'utf-8');
my $result;
my ($time) = $content =~ m/製表時間 :.*?,([\d:]+)/;
undef $self->{quote} if $self;
#
| 3480 | ®õ¦w¬ì | 70.56 | 68.0 | 1,000 | 72.0 | 1,000 | 71.0 | 69.0 | 70.47 | 71.0 | 25,039 | 95/04/03 | °e¥ó¥Ó½Ð¤W¥« |
while ($content =~ s{}{}) {
my $entrybuf = $1;
my ($stock_no) = $entrybuf =~ m{"(\d+)"};
next unless $stock_no == $self->{id};
@{$result}{qw(id name PAvg BidBuy BidBuyVol BidSell BidSellVol HighPrice LowPrice Avg MatchPrice DQty)} =
map {s/,//g; $_} grep { $_ ne ' ' } $entrybuf =~ m/>(?: \s*)?([^<>]+){DQty} /= 1000;
$result->{time} = $time;
}
$self->{quote} = $result if $self;
return $result;
}
1;
=head1 NAME
Finance::TW::EmergingQuote - Check stock quotes from Taiwan Emerging Stock
=head1 SYNOPSIS
use Finance::TW::EmergingQuote;
my $quote = Finance::TW::EmergingQuote->new('3481');
while (1) { print $quote->get->{MatchPrice}.$/; sleep 30 }
=head1 DESCRIPTION
This module provides interface to Emerging Stock price information
available from Taiwan's OTC(over-the-counter market). You could get
the real time quote.
=head1 CLASS METHODS
=over 4
=item new
Create a stock quote object. Resolve the name to symbol
if the argument is not a symbol.
=item resolve
Resolve the company name to stock symbol.
=item get
Get the real time stock information.
Return a hash containing stock information. The keys are:
=over 4
=item DQty
current volume
=item MatchPrice
current price
=item HighPrice
daily high
=item LowPrice
daily low
=back
=back
=head1 AUTHORS
Chia-liang Kao Eclkao@clkao.orgE
=head1 COPYRIGHT
Copyright 2006 by Chia-liang Kao Eclkao@clkao.orgE.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
See L
=cut