File Coverage

blib/lib/Finance/Crypto/Exchange/Kraken/REST/Private.pm
Criterion Covered Total %
statement 20 20 100.0
branch 2 4 50.0
condition n/a
subroutine 5 5 100.0
pod n/a
total 27 29 93.1


line stmt bran cond sub pod time code
1             package Finance::Crypto::Exchange::Kraken::REST::Private;
2             our $VERSION = '0.002';
3 1     1   787 use Moose::Role;
  1         3  
  1         18  
4              
5 1     1   7153 use Digest::SHA qw(hmac_sha512_base64 sha256);
  1         3460  
  1         101  
6 1     1   9 use HTTP::Request::Common qw(POST);
  1         3  
  1         308  
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   110 my ($self, $call, %payload) = @_;
14              
15 31 50       1462 die "Unable to progress, no key set!" unless $self->has_key;
16 31 50       1140 die "Unable to progress, no secret set!" unless $self->has_secret;
17              
18 31         1036 my $uri = $self->_uri->clone;
19 31         337 $uri->path_segments(0, 'private', $call);
20              
21 31         2351 my $nonce = $payload{nonce} = $self->nonce;
22              
23 31         1308 my $req = POST($uri,
24             Content => [ %payload ],
25             'API-Key' => $self->key,
26             );
27              
28 31         14925 $req->header('API-Sign' => $self->_hmac($uri->path, $nonce, $req->content));
29              
30 31         2034 return $req;
31             }
32              
33             sub _hmac {
34 31     31   814 my ($self, $path, $nonce, $content) = @_;
35 31         1408 return hmac_sha512_base64(
36             join("", $path, sha256($nonce . $content)),
37             $self->secret
38             );
39             }
40              
41             with qw(
42             Finance::Crypto::Exchange::Kraken::REST::Private::User::Data
43             Finance::Crypto::Exchange::Kraken::REST::Private::User::Trading
44             Finance::Crypto::Exchange::Kraken::REST::Private::User::Funding
45             Finance::Crypto::Exchange::Kraken::REST::Private::Websockets
46             );
47              
48             1;
49              
50             __END__
51              
52             =pod
53              
54             =encoding UTF-8
55              
56             =head1 NAME
57              
58             Finance::Crypto::Exchange::Kraken::REST::Private - Role for Kraken "private" API calls
59              
60             =head1 VERSION
61              
62             version 0.002
63              
64             =head1 SYNOPSIS
65              
66             package Foo;
67             with qw(Finance::Crypto::Exchange::Kraken::REST::Private);
68              
69             =head1 DESCRIPTION
70              
71             This role introduces all the private API calls Kraken supports.
72              
73             =head1 SEE ALSO
74              
75             =over
76              
77             =item * L<Finance::Crypto::Exchange::Kraken::REST::Private::User::Data>
78              
79             =item * L<Finance::Crypto::Exchange::Kraken::REST::Private::User::Trading>
80              
81             =item * L<Finance::Crypto::Exchange::Kraken::REST::Private::User::Funding>
82              
83             =item * L<Finance::Crypto::Exchange::Kraken::REST::Private::Websockets>
84              
85             =back
86              
87             =head1 AUTHOR
88              
89             Wesley Schwengle <waterkip@cpan.org>
90              
91             =head1 COPYRIGHT AND LICENSE
92              
93             This software is Copyright (c) 2020 by Wesley Schwengle.
94              
95             This is free software, licensed under:
96              
97             The (three-clause) BSD License
98              
99             =cut