File Coverage

blib/lib/Finance/Crypto/Exchange/Kraken/REST/Private.pm
Criterion Covered Total %
statement 23 23 100.0
branch 2 4 50.0
condition n/a
subroutine 5 5 100.0
pod n/a
total 30 32 93.7


line stmt bran cond sub pod time code
1             package Finance::Crypto::Exchange::Kraken::REST::Private;
2             our $VERSION = '0.004';
3 4     4   178878 use Moose::Role;
  4         486613  
  4         52  
4              
5 4     4   24401 use Digest::SHA qw(hmac_sha512_base64 sha256);
  4         12837  
  4         419  
6 4     4   455 use HTTP::Request::Common qw(POST);
  4         20244  
  4         1399  
7              
8             # ABSTRACT: Role for Kraken "private" API calls
9              
10             requires qw(call nonce has_key has_secret key secret);
11              
12             sub _private {
13 31     31   131 my ($self, $call, %payload) = @_;
14              
15 31 50       2154 die "Unable to progress, no key set!" unless $self->has_key;
16 31 50       1752 die "Unable to progress, no secret set!" unless $self->has_secret;
17              
18 31         1403 my $uri = $self->_uri->clone;
19 31         488 $uri->path_segments(0, 'private', $call);
20              
21 31         3060 my $nonce = $payload{nonce} = $self->nonce;
22              
23 31         1789 my $req = POST($uri,
24             Content => [ %payload ],
25             'API-Key' => $self->key,
26             );
27              
28 31         19373 $req->header('API-Sign' => $self->_hmac($uri->path, $nonce, $req->content));
29              
30 31         2436 return $req;
31             }
32              
33             sub _hmac {
34 32     32   920 my ($self, $path, $nonce, $content) = @_;
35 32         2275 my $hmac = hmac_sha512_base64(
36             join("", $path, sha256($nonce . $content)),
37             $self->secret
38             );
39              
40 32         166 while (length($hmac) % 4) {
41 64         257 $hmac .= '=';
42             }
43 32         174 return $hmac;
44              
45             }
46              
47             with qw(
48             Finance::Crypto::Exchange::Kraken::REST::Private::User::Data
49             Finance::Crypto::Exchange::Kraken::REST::Private::User::Trading
50             Finance::Crypto::Exchange::Kraken::REST::Private::User::Funding
51             Finance::Crypto::Exchange::Kraken::REST::Private::Websockets
52             );
53              
54             1;
55              
56             __END__
57              
58             =pod
59              
60             =encoding UTF-8
61              
62             =head1 NAME
63              
64             Finance::Crypto::Exchange::Kraken::REST::Private - Role for Kraken "private" API calls
65              
66             =head1 VERSION
67              
68             version 0.004
69              
70             =head1 SYNOPSIS
71              
72             package Foo;
73             with qw(Finance::Crypto::Exchange::Kraken::REST::Private);
74              
75             =head1 DESCRIPTION
76              
77             This role introduces all the private API calls Kraken supports.
78              
79             =head1 SEE ALSO
80              
81             =over
82              
83             =item * L<Finance::Crypto::Exchange::Kraken::REST::Private::User::Data>
84              
85             =item * L<Finance::Crypto::Exchange::Kraken::REST::Private::User::Trading>
86              
87             =item * L<Finance::Crypto::Exchange::Kraken::REST::Private::User::Funding>
88              
89             =item * L<Finance::Crypto::Exchange::Kraken::REST::Private::Websockets>
90              
91             =back
92              
93             =head1 AUTHOR
94              
95             Wesley Schwengle <waterkip@cpan.org>
96              
97             =head1 COPYRIGHT AND LICENSE
98              
99             This software is Copyright (c) 2020 by Wesley Schwengle.
100              
101             This is free software, licensed under:
102              
103             The (three-clause) BSD License
104              
105             =cut