File Coverage

lib/Finance/GDAX/API/Quote.pm
Criterion Covered Total %
statement 30 30 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod 1 1 100.0
total 39 39 100.0


line stmt bran cond sub pod time code
1             package Finance::GDAX::API::Quote;
2             our $VERSION = '0.01';
3 1     1   64411 use 5.20.0;
  1         3  
4 1     1   5 use warnings;
  1         2  
  1         24  
5 1     1   440 use Moose;
  1         397023  
  1         7  
6 1     1   6519 use JSON;
  1         1  
  1         9  
7 1     1   729 use REST::Client;
  1         33753  
  1         30  
8 1     1   308 use Finance::GDAX::API::URL;
  1         4  
  1         63  
9 1     1   596 use namespace::autoclean;
  1         6116  
  1         4  
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 1     1 1 2 my $self = shift;
89 1         30 my $url = Finance::GDAX::API::URL->new;
90 1         24 $url->debug($self->debug);
91 1         4 $url->add('products');
92 1         17 $url->add($self->product);
93 1         4 $url->add('ticker');
94            
95 1         8 my $client = REST::Client->new;
96 1         3719 $client->GET($url->get);
97              
98 1         690904 my $json = JSON->new;
99 1         8 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