File Coverage

blib/lib/Finance/Crypto/Exchange/Kraken/REST/Public.pm
Criterion Covered Total %
statement 50 50 100.0
branch 2 2 100.0
condition n/a
subroutine 14 14 100.0
pod 9 9 100.0
total 75 75 100.0


line stmt bran cond sub pod time code
1             package Finance::Crypto::Exchange::Kraken::REST::Public;
2             our $VERSION = '0.004';
3 4     4   158343 use Moose::Role;
  4         460745  
  4         15  
4              
5             # ABSTRACT: Role for Kraken "public" API calls
6              
7             requires qw(call);
8              
9 4     4   23217 use HTTP::Request::Common qw(POST);
  4         25708  
  4         333  
10 4     4   3370 use Types::Standard qw( Int Str Enum);
  4         543403  
  4         78  
11 4     4   14813 use Params::ValidationCompiler qw(validation_for);
  4         89977  
  4         3261  
12              
13             sub _public {
14 12     12   76 my ($self, $call, %payload) = @_;
15              
16 12         714 my $uri = $self->_uri->clone;
17 12         266 $uri->path_segments(0, 'public', $call);
18              
19 12 100       1458 return POST(
20             $uri,
21             %payload ? (Content => [%payload]) : (),
22             );
23             }
24              
25             sub get_server_time {
26 1     1 1 9736 my $self = shift;
27 1         17 my $req = $self->_public('Time');
28 1         302 return $self->call($req);
29             }
30              
31             sub get_system_status {
32 1     1 1 9588 my $self = shift;
33 1         6 my $req = $self->_public('SystemStatus');
34 1         339 return $self->call($req);
35             }
36              
37             {
38             my $validator = validation_for(
39             name => 'get_asset_info',
40             params => {
41             info => {
42             type => Enum [qw(info)],
43             optional => 1,
44             },
45             aclass => {
46             type => Enum [qw(currency)],
47             optional => 1,
48             },
49             asset => {
50             type => Str,
51             optional => 1,
52             },
53             },
54             );
55              
56             sub get_asset_info {
57 2     2 1 32762 my $self = shift;
58 2         88 my %args = $validator->(@_);
59 2         100 my $req = $self->_public('Assets', %args);
60 2         1336 return $self->call($req);
61             }
62             }
63              
64             {
65              
66             my $validator = validation_for(
67             name => 'get_tradable_asset_pairs',
68             params => {
69             info => {
70             type => Enum [qw(info leverage fees margin)],
71             optional => 1,
72             },
73             pair => {
74             type => Str,
75             optional => 1,
76             },
77             },
78             );
79              
80             sub get_tradable_asset_pairs {
81 2     2 1 19055 my $self = shift;
82 2         86 my %args = $validator->(@_);
83 2         84 my $req = $self->_public('AssetPairs', %args);
84 2         938 return $self->call($req);
85             }
86              
87             }
88              
89             {
90              
91             my $validator = validation_for(
92             name => 'get_ticker_information',
93             params => { pair => { type => Str, }, },
94             );
95              
96             sub get_ticker_information {
97 1     1 1 9500 my $self = shift;
98 1         48 my %args = $validator->(@_);
99 1         42 my $req = $self->_public('Ticker', %args);
100 1         601 return $self->call($req);
101             }
102             }
103              
104             {
105             my $validator = validation_for(
106             name => 'get_ohlc_data',
107             params => {
108             pair => { type => Str, },
109             interval => {
110             optional => 1,
111             type => Enum [qw(1 5 15 30 60 240 1440 10080 21600)]
112             },
113             since => { optional => 1, }
114             },
115             );
116              
117             sub get_ohlc_data {
118 1     1 1 16628 my $self = shift;
119 1         47 my %args = $validator->(@_);
120 1         58 my $req = $self->_public('OHLC', %args);
121 1         653 return $self->call($req);
122             }
123             }
124              
125             {
126             my $validator = validation_for(
127             name => 'get_order_book',
128             params => {
129             pair => { type => Str, },
130             count => {
131             optional => 1,
132             type => Int,
133             },
134             },
135             );
136              
137             sub get_order_book {
138 2     2 1 19956 my $self = shift;
139 2         86 my %args = $validator->(@_);
140 2         92 my $req = $self->_public('Depth', %args);
141 2         1181 return $self->call($req);
142             }
143             }
144              
145             {
146             my $validator = validation_for(
147             name => 'get_recent_trades',
148             params => {
149             pair => { type => Str, },
150             since => { optional => 1, },
151             },
152             );
153              
154             sub get_recent_trades {
155 1     1 1 9705 my $self = shift;
156 1         50 my %args = $validator->(@_);
157 1         43 my $req = $self->_public('Trades', %args);
158 1         631 return $self->call($req);
159             }
160             }
161              
162             {
163              
164             my $validator = validation_for(
165             name => 'get_recent_spread_data',
166             params => {
167             pair => { type => Str, },
168             since => { optional => 1, },
169             },
170             );
171              
172             sub get_recent_spread_data {
173 1     1 1 9638 my $self = shift;
174 1         48 my %args = $validator->(@_);
175 1         43 my $req = $self->_public('Spread', %args);
176 1         592 return $self->call($req);
177             }
178              
179             }
180              
181             1;
182              
183             __END__
184              
185             =pod
186              
187             =encoding UTF-8
188              
189             =head1 NAME
190              
191             Finance::Crypto::Exchange::Kraken::REST::Public - Role for Kraken "public" API calls
192              
193             =head1 VERSION
194              
195             version 0.004
196              
197             =head1 SYNOPSIS
198              
199             package Foo;
200             use Moose;
201             with qw(Finance::Crypto::Exchange::Kraken::REST::Public);
202              
203             =head1 DESCRIPTION
204              
205             This role introduces all the public API calls Kraken supports. For extensive
206             information please have a look at the
207             L<Kraken API manual|https://www.kraken.com/features/api#public-market-data>
208              
209             =head1 METHODS
210              
211             =head2 get_server_time
212              
213             L<https://api.kraken.com/0/public/Time>
214              
215             =head2 get_system_status
216              
217             L<https://api.kraken.com/0/public/SystemStatus>
218              
219             =head2 get_asset_info
220              
221             L<https://api.kraken.com/0/public/Asset>
222              
223             =head3 Accepted parameters
224              
225             =over
226              
227             =item info (optional)
228              
229             C<info> all info (default)
230              
231             =item aclass (optional)
232              
233             C<currency> (default)
234              
235             =item asset (optional)
236              
237             C<all> (default)
238              
239             =back
240              
241             =head2 get_tradable_asset_pairs
242              
243             L<https://api.kraken.com/0/public/AssetPairs>
244              
245             =head2 get_ticker_information
246              
247             L<https://api.kraken.com/0/public/Ticker>
248              
249             =head2 get_ohlc_data
250              
251             L<https://api.kraken.com/0/public/OHLC>
252              
253             =head2 get_order_book
254              
255             L<https://api.kraken.com/0/public/Depth>
256              
257             =head2 get_recent_trades
258              
259             L<https://api.kraken.com/0/public/Trades>
260              
261             =head2 get_recent_spread_data
262              
263             L<https://api.kraken.com/0/public/Spread>
264              
265             =head1 AUTHOR
266              
267             Wesley Schwengle <waterkip@cpan.org>
268              
269             =head1 COPYRIGHT AND LICENSE
270              
271             This software is Copyright (c) 2020 by Wesley Schwengle.
272              
273             This is free software, licensed under:
274              
275             The (three-clause) BSD License
276              
277             =cut