Finance-Bank-Kraken
view release on metacpan or search on metacpan
lib/Finance/Bank/Kraken.pm view on Meta::CPAN
my $uripath = sprintf "/0/%s/%s", $_[0]?"private":"public", $_[1];
my $req = new HTTP::Request($_[0]?'POST':'GET');
my $ua = new LWP::UserAgent('agent' => "perl(Finance::Bank::Kraken) api client/".$VERSION);
my $qry = defined $_[2]?(join "&", @{$_[2]}):undef;
if ($_[0]) {
$req->uri($self->{'uri'} . $uripath);
$req->content(sprintf "nonce=%d%s", $self->{'nonce'}, defined $qry?"&$qry":"");
$req->header("API-Key" => $self->{'key'});
$req->header("API-Sign" => hmac_sha512_base64(
$uripath . sha256($self->{'nonce'} . $req->content),
$self->{'secret'})
);
$self->{'nonce'}++
} else {
$req->uri(sprintf "%s%s%s", $self->{'uri'}, $uripath, defined $qry?"?$qry":"")
}
my $res = $ua->request($req);
$res->is_success?$res->content:$res->status_line
}
1;
__END__
=head1 NAME
Finance::Bank::Kraken - api.kraken.com connector
=head1 VERSION
0.3
=head1 SYNOPSIS
require Finance::Bank::Kraken;
$api = new Finance::Bank::Kraken;
$api->key($mykrakenkey);
$api->secret($mykrakensecret);
$result = $api->call(Private, $method, [$arg1, $arg2, ..]);
=head1 DESCRIPTION
This module allows to connect to the api of the bitcoin market Kraken.
Please see L<the Kraken API documentation|https://www.kraken.com/help/api> for a catalog of api methods.
=head1 METHODS
=over 4
=item $api = new Finance::Bank::Kraken
The constructor. Returns a C<Finance::Bank::Kraken> object.
=item $api->key($key)
Sets or gets the API key.
=item $api->secret($secret)
Sets the API secret to C<$secret> or returns the API secret base64 decoded.
=item $result = $api->call(Public, $method)
=item $result = $api->call(Private, $method)
=item $result = $api->call(Private, $method, [$param1, $param2, ..])
Calls the C<Public> or C<Private> API method C<$method> (with the given C<$params>, where applicable) and returns either the JSON encoded result string or an error message (C<code> C<message>).
=back
=head1 DEPENDENCIES
=over 8
=item L<HTTP::Request>
=item L<LWP::UserAgent>
=item L<MIME::Base64>
=item L<Digest::SHA>
=back
=head1 EXAMPLES
=head2 get current XLTC market price in EUR
use Finance::Bank::Kraken;
use JSON;
my $kraken = new Finance::Bank::Kraken;
my $res = $kraken->call(Public, 'Ticker', ['pair=XLTCZEUR,XXBTZEUR']);
printf "1 XLTC is %f EUR\n",
from_json($res)->{'result'}->{'XLTCZEUR'}->{'c'}[0]
unless $res =~ /^5/;
=head2 get XLTC account balance
use Finance::Bank::Kraken;
use JSON;
my $kraken = new Finance::Bank::Kraken;
$kraken->key("mysupersecretkey");
$kraken->secret("mysupersecretsecret");
my $res = $kraken->call(Private, 'Balance');
printf "balance: %f XLTC\n",
from_json($res)->{'result'}->{'XLTC'} unless $res =~ /^5/;
=head1 Q&A
=over 8
=item Why does C<call> return a 404?
Probably you misspelled the method. Please check the API documentation and keep in mind the methods are case sensitive.
=item Why does C<call> return a 500?
( run in 1.539 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )