Finance-Quote-Grab

 view release on metacpan or  search on metacpan

devel/Casablanca.pm  view on Meta::CPAN

sub casablanca_quotes {
  my ($fq, @symbol_list) = @_;
  my $ua = $fq->user_agent;
  my %quotes;

  foreach my $symbol (@symbol_list) {
    my $url = make_url ($symbol);

    my $req = HTTP::Request->new ('GET', $url);
    $ua->prepare_request ($req);
    $req->accept_decodable; # we know decoded_content() below
    $req->user_agent (__PACKAGE__."/$VERSION " . $req->user_agent);
    ### Request: $req->as_string

    my $resp = $ua->request ($req);
    resp_to_quotes ($fq, $symbol, $resp, \%quotes);
  }
  return wantarray() ? %quotes : \%quotes;
}

# The "Reference price" seems to be the previous close, ie. reference for

devel/Casablanca.pm  view on Meta::CPAN

# store to hashref $quotes for $symbol based on HTTP::Response in $resp
sub resp_to_quotes {
  my ($fq, $symbol, $resp, $quotes) = @_;

  $quotes->{$symbol,'method'} = 'casablanca';
  $quotes->{$symbol,'currency'} = 'MAD';
  $quotes->{$symbol,'source'} = __PACKAGE__;
  $quotes->{$symbol,'success'} = 1;

  # defaults to latin1, which is right
  my $content = $resp->decoded_content (raise_error => 1, charset => 'none');
  if (! $resp->is_success) {
    $quotes->{$symbol,'success'}  = 0;
    $quotes->{$symbol,'errormsg'} = $resp->status_line;
    return;
  }
  $content =~ tr/\240/ /;

  if ($content =~ /Pas de r.sultat/) {
    $quotes->{$symbol,'success'}  = 0;
    $quotes->{$symbol,'errormsg'} = 'No information';

devel/ghana.pl  view on Meta::CPAN

                      }
                      return 1; # continue being called
                    });


  my $url = Finance::Quote::Ghana::GHANA_MARKET_URL();
  # $url = 'http://user42.tuxfamily.org/finance-quote-grab/index.html';

  require HTTP::Request;
  my $req = HTTP::Request->new ('GET', $url);
  $req->accept_decodable; # using decoded_content() below
  $ua->prepare_request ($req);

  my $user_agent =
    'User-Agent: Mozilla/5.0 '
    . "Finance::Quote::Ghana/$Finance::Quote::Ghana::VERSION "
    . $req->user_agent;
  # $user_agent =~ s/::/-/g;
  $req->user_agent ($user_agent);

  # $req->user_agent ('User-Agent: Mozilla/5.0');

devel/lib/Finance/Quote/ATHEX.pm  view on Meta::CPAN

  my $ua = $fq->user_agent;
  my %quotes;

  foreach my $symbol (@symbol_list) {
    next unless defined (my $cid = symbol_to_cid ($fq, \%quotes, $symbol));
    my $url = ATHEX_STOCKINFO_BASE_URL . URI::Escape::uri_escape($cid);

    require HTTP::Request;
    my $req = HTTP::Request->new ('GET', $url);
    $ua->prepare_request ($req);
    $req->accept_decodable; # we have decoded_content() below
    $req->user_agent (__PACKAGE__."/$VERSION " . $req->user_agent);
    ### req: $req->as_string

    my $resp = $ua->request ($req);
    stockinfo_to_quotes ($fq, $resp, \%quotes, $symbol);


    # my $url = ATHEX_LAST30_BASE_URL . URI::Escape::uri_escape($symbol);
    # last30_to_quotes ($fq, $resp, \%quotes, $symbol);
  }

devel/lib/Finance/Quote/ATHEX.pm  view on Meta::CPAN

}

sub symbol_to_cid {
  my ($fq, $quotes, $symbol) = @_;
  my $ua = $fq->user_agent;
  my $url = ATHEX_SEARCH_BASE_URL . URI::Escape::uri_escape($symbol);

  require HTTP::Request;
  my $req = HTTP::Request->new ('GET', $url);
  $ua->prepare_request ($req);
  $req->accept_decodable; # we have decoded_content() below
  $req->user_agent (__PACKAGE__."/$VERSION " . $req->user_agent);
  ### req: $req->as_string

  my $resp = $ua->request ($req);
  _search_resp_to_cid ($resp, $quotes, $symbol);
}
sub _search_resp_to_cid {
  my ($resp, $quotes, $symbol) = @_;
  if (! $resp->is_success) {
    $quotes->{$symbol,'errormsg'} = $resp->status_line;
    return undef;
  }
  my $content = $resp->decoded_content (raise_error => 1, charset => 'none');

  if ($content =~ /Your search didn't return any results/) {
    $quotes->{$symbol,'errormsg'} = 'No such symbol';
    return undef;
  }

  if ($content =~ m{\Qhttp://www.helex.gr/content/en/Companies/ListedCo/Profiles/Profile.asp?cid=\E(\d+)}) {
    return $1;
  } else {
    $quotes->{$symbol,'errormsg'} = 'Oops, CID number not matched';

devel/lib/Finance/Quote/ATHEX.pm  view on Meta::CPAN

  ### ATHEX stockinfo_to_quotes() ...

  $quotes->{$symbol,'method'}   = 'athex';
  $quotes->{$symbol,'source'}   = __PACKAGE__;
  $quotes->{$symbol,'success'}  = 0;

  if (! $resp->is_success) {
    $quotes->{$symbol,'errormsg'} = $resp->status_line;
    return undef;
  }
  my $content = $resp->decoded_content (raise_error => 1, charset => 'none');

  require HTML::TableExtract;
  {
    my $te = HTML::TableExtract->new
      (headers => [qr/Last.*Price/is,
                   qr/Change[^%]*$/is,
                   qr/Change.*%/is,
                  ]);
    $te->parse($content);
    if (! $te->tables) {

devel/lib/Finance/Quote/ATHEX.pm  view on Meta::CPAN

  ### ATHEX last30_to_quotes() ...

  $quotes->{$symbol,'method'}  = 'athex';
  $quotes->{$symbol,'source'}  = __PACKAGE__;
  $quotes->{$symbol,'success'} = 0;

  if (! $resp->is_success) {
    $quotes->{$symbol,'errormsg'} = $resp->status_line;
    return;
  }
  my $content = $resp->decoded_content (raise_error => 1, charset => 'none');

  # message in page if bad symbol
  if ($content =~ /Your search didn't return any results/) {
    ### unknown symbol ...
    $quotes->{$symbol,'errormsg'} = 'Unknown symbol';
    return;
  }

  unless ($content
          =~ m{Share Closing Prices: ([A-Z]+)[^-]*-[^>]*>([^<]+)</a>}) {

devel/lib/Finance/Quote/Barchart.pm  view on Meta::CPAN

  my %quotes;

  foreach my $symbol (@symbol_list) {
    my $commodity = $symbol;
    $commodity =~ s/[A-Z][0-9][0-9]$//;
    my $url = BARCHART_EXCHANGE_BASE_URL . URI::Escape::uri_escape($commodity);

    require HTTP::Request;
    my $req = HTTP::Request->new ('GET', $url);
    $ua->prepare_request ($req);
    $req->accept_decodable; # we know decoded_content() below
    $req->user_agent (__PACKAGE__."/$VERSION " . $req->user_agent);
    ### req: $req->as_string

    my $resp = $ua->request ($req);
    resp_to_quotes ($fq, $symbol, $resp, \%quotes);
  }
  return wantarray() ? %quotes : \%quotes;
}

sub resp_to_quotes {
  my ($fq, $target_symbol, $resp, $quotes) = @_;

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

  # eg. "   <B>CRUDE OIL</B> Delayed Futures -20:10 - Sunday, 19 June"
  #     "   <B>SIMEX NIKKEI 225</B> Delayed Futures -18:20 - Tuesday, 12 December</td>"
  #     "   <B>OATS   </B> Daily Futures -     Friday, 20 April                 </td>
  $content =~ m{([^<>\r\n]+) *</B> Delayed Futures *- *([0-9]+:[0-9]+) *- *[A-Za-z]+, ([0-9]+ [A-Za-z]+)}is
    or die 'Barchart: ifutpage name/date/time not matched';
  my $name = $1;
  my $head_time = $2;
  my $head_date = $3;
  ### head

devel/rba.pl  view on Meta::CPAN

                      }
                      return 1; # continue being called
                    });


  my $url = Finance::Quote::RBA::GHANA_MARKET_URL();
  # $url = 'http://user42.tuxfamily.org/finance-quote-grab/index.html';

  require HTTP::Request;
  my $req = HTTP::Request->new ('GET', $url);
  $req->accept_decodable; # using decoded_content() below
  $ua->prepare_request ($req);

  my $user_agent =
    'User-Agent: Mozilla/5.0 '
    . "Finance::Quote::RBA/$Finance::Quote::RBA::VERSION "
    . $req->user_agent;
  # $user_agent =~ s/::/-/g;
  $req->user_agent ($user_agent);

  # $req->user_agent ('User-Agent: Mozilla/5.0');

lib/Finance/Quote/Ghana.pm  view on Meta::CPAN


  # The gse server (an Apache) will serve gzipped, so accept_decodable()
  # here saves some data transmission.
  #
  # user_agent() is set only to the package.  Would normally include the
  # libwww-perl identifier too, but some bad setup on the gse server gives
  # "406 Not acceptable" if more than one identifier.
  #
  require HTTP::Request;
  my $req = HTTP::Request->new ('GET', GHANA_MARKET_URL);
  $req->accept_decodable; # using decoded_content() below
  $req->user_agent (__PACKAGE__."/".$VERSION);
  ### req: $req->as_string

  my $ua = $fq->user_agent;
  my $resp = $ua->request ($req);
  ### resp headers: $resp->headers->as_string

  my %quotes;
  _parse ($fq, $resp, \%quotes, \@symbol_list);
  return wantarray() ? %quotes : \%quotes;

lib/Finance/Quote/Ghana.pm  view on Meta::CPAN

  foreach my $symbol (@$symbol_list) {
    $quotes->{$symbol,'method'}   = 'ghana';
    $quotes->{$symbol,'source'}   = __PACKAGE__;
    $quotes->{$symbol,'success'}  = 0;
  }

  if (! $resp->is_success) {
    _errormsg ($quotes, $symbol_list, $resp->status_line);
    return;
  }
  my $content = $resp->decoded_content (raise_error => 1, charset => 'none');

  # Eg. <span class="glyphicon glyphicon-calendar"></span> February 22, 2019</div>
  $content =~ m{glyphicon-calendar.*?([a-z]+) (\d{1,2}), (\d\d\d\d)}i
    or die "GSE: daily page cannot find trade date\n";
  my $date = "$1/$2/$3";  # "October/03/2014"

  require HTML::TableExtract;
  my $te = HTML::TableExtract->new
    (headers => [ # qr/Session/i,
                 qr/ISIN/i,

lib/Finance/Quote/MGEX.pm  view on Meta::CPAN

    }
    push @{$aq_symbol_list{$key}}, $symbol;
  }
  ### @aq_keys
  ### %aq_symbol_list

  foreach my $aq (@aq_keys) {
    require HTTP::Request;
    my $req = HTTP::Request->new ('GET', $aq_url{$aq});
    $ua->prepare_request ($req);
    $req->accept_decodable; # we use decoded_content() below
    $req->user_agent (__PACKAGE__."/$VERSION " . $req->user_agent);
    ### req: $req->as_string

    my $resp = $ua->request ($req);
    resp_to_quotes ($fq, $resp, \%quotes, $aq_symbol_list{$aq});
  }
  return wantarray() ? %quotes : \%quotes;
}

sub symbol_to_commodity {

lib/Finance/Quote/MGEX.pm  view on Meta::CPAN

  foreach my $symbol (@$symbol_list) {
    $quotes->{$symbol,'method'}  = 'mgex';
    $quotes->{$symbol,'source'}  = __PACKAGE__;
    $quotes->{$symbol,'success'} = 0;  # false if not in returned
  }

  if (! $resp->is_success) {
    _errormsg ($quotes, $symbol_list, $resp->status_line);
    return;
  }
  my $content = $resp->decoded_content (raise_error => 1);

  $content = _javascript_document_write ($content);
  ### $content
  $content =~ s/&nbsp;/ /g;

  my $page_date;
  if ($content =~ /for ([a-zA-Z]+ [0-9]{1,2}, [0-9]{4})/) {
    $page_date = $1;
    ### $page_date
  }

lib/Finance/Quote/MLC.pm  view on Meta::CPAN

sub mlc_quotes {
  my ($fq, @symbol_list) = @_;
  my $ua = $fq->user_agent;
  my %quotes;

  foreach my $symbol (@symbol_list) {
    my $url = make_url ($symbol);

    my $req = HTTP::Request->new ('GET', $url);
    $ua->prepare_request ($req);
    $req->accept_decodable; # we know decoded_content() below
    $req->user_agent (__PACKAGE__."/$VERSION " . $req->user_agent);
    ### Request: $req->as_string

    my $resp = $ua->request ($req);
    resp_to_quotes ($fq, $resp, \%quotes, $symbol);
  }
  return wantarray() ? %quotes : \%quotes;
}

# Sample url:

lib/Finance/Quote/MLC.pm  view on Meta::CPAN

#   historicalProduct1funds[1]="MLC Property Securities Fund,MasterKey Superannuation (Gold Star),29 March 2007,64.71567,0.00000";
#
sub resp_to_quotes {
  my ($fq, $resp, $quotes, $symbol) = @_;

  $quotes->{$symbol,'method'}   = 'mlc';
  $quotes->{$symbol,'currency'} = 'AUD';
  $quotes->{$symbol,'source'}   = __PACKAGE__;
  $quotes->{$symbol,'success'}  = 1;

  my $content = $resp->decoded_content (raise_error => 1, charset => 'none');
  if (! $resp->is_success) {
    $quotes->{$symbol,'success'}  = 0;
    $quotes->{$symbol,'errormsg'} = $resp->status_line;
    return;
  }

  if ($content =~ /No unit prices available/i) {
    $quotes->{$symbol,'success'}  = 0;
    $quotes->{$symbol,'errormsg'} = 'No unit prices available';
    return;

lib/Finance/Quote/RBA.pm  view on Meta::CPAN

  'https://www.rba.gov.au/copyright/index.html';

sub rba_quotes {
  my ($fq, @symbol_list) = @_;
  if (! @symbol_list) { return; }

  my $ua = $fq->user_agent;
  require HTTP::Request;
  my $req = HTTP::Request->new ('GET', EXCHANGE_RATES_URL);
  $ua->prepare_request ($req);
  $req->accept_decodable; # using decoded_content() below
  $req->user_agent (__PACKAGE__."/$VERSION " . $req->user_agent);

  my $resp = $ua->request ($req);
  my %quotes;
  _parse ($fq, $resp, \%quotes, \@symbol_list);
  return wantarray() ? %quotes : \%quotes;
}

sub _parse {
  my ($fq, $resp, $quotes, $symbol_list) = @_;

lib/Finance/Quote/RBA.pm  view on Meta::CPAN

  foreach my $symbol (@$symbol_list) {
    $quotes->{$symbol,'method'}  = 'rba';
    $quotes->{$symbol,'source'}  = __PACKAGE__;
    $quotes->{$symbol,'success'} = 0;
  }

  if (! $resp->is_success) {
    _errormsg ($quotes, $symbol_list, $resp->status_line);
    return;
  }
  my $content = $resp->decoded_content (raise_error => 1, charset => 'none');

  # mung <tr id="USD"> to add <td>USD</td> so it appears in the TableExtract
  $content =~ s{<tr>}{<tr><td></td>}ig;
  $content =~ s{(<tr +id="([^"]*)">)}{$1<td>$2</td>}ig;

  require HTML::TableExtract;
  my $te = HTML::TableExtract->new
    (
     # now in a <caption> instead of a heading
     # headers => [qr/Units of Foreign Currencies per/i],



( run in 0.709 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )