Finance::Currency::Convert::SCSB - Query currency exchange rates from SCSB (Shanghai Commercial and Savings Bank)
v0.1.0
This module crawl and parses currency exchange rates listed on this web: https://ibank.scsb.com.tw/netbank.portal?_nfpb=true&_pageLabel=page_other12&_nfls=false . All prices on this page are in TWD (Taiwan Dollar.) For this reason, it can only convert some non-TWD currency to TWD.
The following functions are exportable, but not exported by default.
Some annotations with fictional Types are used in the following documentation just for the purpose of explaination. No Type-validation are implemented, nor are they defined. Not in this module.
"Num" referrer to a number, "Currency" is a short string such as 'TWD', 'USD'. The notation `Maybe[T]` means that the variable can contain a value either be of type T, or undef. See: Types::Standard or Moose::Util::TypeConstraints for more description of these notations.
undef
Definition:
($error :Maybe[Str], $result :Maybe[Num]) = convert_currency( $amount :Num $from :Currency, $to :Currency )
When it is successful, $error is undef and $result contained the parsed output.
$error
$result
When error of some kind happens, $error contains the error message and $result is undef.
Example Usage:
# Error-checking my ($err, $n) = convert_currency(100, 'USD', 'TWD'); die "Error: $err": if $err; say "100 USD is about $n TWD"; # Ignore error message. Checks the result directly. my $n = convert_currency(100, 'USD', 'TWD'); if ( defined($n) ) { say "100 USD is about $n TWD"; } else { say "Failed to convert 100 USD to TWD"; }
With this function, the entire exchange rate table are parsed and returned in the special strucutre.
($error :Maybe[Str], $result :Maybe[ArrayRef[Rate]]) = convert_currency( $amount :Num, $from :Currency, $to :Currency )
Usage:
# Error-checking my ($err, $o) = get_currencies(); die "Error: $err": if $err; do_something($o); # Ignore error message. Checks the result directly. my $o = get_currencies(); if ($o) { ... } else { ... }
The "Rate" type is a HashRef with 5 specific key-value pairs that looks like this:
{ currency => "USD", zh_currency_name => "美金現金", en_currency_name => "USD CASH", buy_at => 33.06, sell_at => 33.56 }
This structure is just a directly translation of the rate exchange table shown on the source web page.
Kang-min Liu <gugod@gugod.org>
This is free software, licensed under:
The MIT (X11) License
To install Finance::Currency::Convert::SCSB, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Finance::Currency::Convert::SCSB
CPAN shell
perl -MCPAN -e shell install Finance::Currency::Convert::SCSB
For more information on module installation, please visit the detailed CPAN module installation guide.