blib/lib/Finance/GDAX/API/Quote.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 44 CC 1 SCAR 6.9
CC
1
Cov
0%
get
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Finance::GDAX::API::Quote;
2 our $VERSION = '0.01';
3 use 5.20.0;
4 use warnings;
5 use Moose;
6 use JSON;
7 use REST::Client;
8 use Finance::GDAX::API::URL;
9 use namespace::autoclean;
10  
11  
12 =head1 NAME
13  
14 Finance::GDAX::API::Quote - Get a quote from the GDAX
15  
16 =head1 SYNOPSIS
17  
18 use Finanace::GDAX::API::Quote;
19 my $quote = Finance::GDAX::API::Quote->new(product => 'BTC-USD')->get;
20 say $$quote{price};
21 say $$quote{bid};
22 say $$quote{ask};
23  
24 =head1 DESCRIPTION
25  
26 Gets a quote from the GDAX for the specified "product". These quotes
27 do not require GDAX API keys, but they suggesting keeping traffic low.
28  
29 More detailed information can be retrieve about products and history
30 using API keys with other classes like Finance::GDAX::API::Product
31  
32 Currently, the supported products are:
33  
34 BTC-USD
35 BTC-GBP
36 BTC-EUR
37 ETH-BTC
38 ETH-USD
39 LTC-BTC
40 LTC-USD
41 ETH-EUR
42  
43 These are not hard-coded, but the default is BTC-USD, so if any are
44 added by GDAX in the future, it should work find if you can find the
45 product code.
46  
47 Quote is returned as a hashref with the (currently) following keys:
48  
49 trade_id
50 price
51 size
52 bid
53 ask
54 volume
55 time
56  
57 =head1 ATTRIBUTES
58  
59 =head2 C<debug> (default: 1)
60  
61 Bool that sets debug mode (will use sandbox). Defaults to true
62 (1). Debug mode does not seem to give real quotes.
63  
64 =head2 C<product> (default: "BTC-USD")
65  
66 The product code for which to return the quote.
67  
68 =cut
69  
70 has 'product' => (is => 'rw',
71 isa => 'Str',
72 default => 'BTC-USD',
73 );
74 has 'debug' => (is => 'rw',
75 isa => 'Bool',
76 default => 1,
77 );
78  
79 =head1 METHODS
80  
81 =head2 C<get>
82  
83 Returns a quote for the desired product.
84  
85 =cut
86  
87 sub get {
88 my $self = shift;
89 my $url = Finance::GDAX::API::URL->new;
90 $url->debug($self->debug);
91 $url->add('products');
92 $url->add($self->product);
93 $url->add('ticker');
94
95 my $client = REST::Client->new;
96 $client->GET($url->get);
97  
98 my $json = JSON->new;
99 return $json->decode($client->responseContent);
100 }
101  
102 __PACKAGE__->meta->make_immutable;
103 1;
104  
105  
106 =head1 AUTHOR
107  
108 Mark Rushing <mark@orbislumen.net>
109  
110 =head1 COPYRIGHT AND LICENSE
111  
112 This software is copyright (c) 2017 by Home Grown Systems, SPC.
113  
114 This is free software; you can redistribute it and/or modify it under
115 the same terms as the Perl 5 programming language system itself.
116  
117 =cut
118