| 1 | package Finance::GDAX::API::Quote; | ||
| 2 | 1 | our $VERSION = '0.01'; | |
| 3 | 1 | ▶ | use 5.20.0; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use JSON; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 1 | ▶ | use REST::Client; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use Finance::GDAX::API::URL; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 1 | ▶ | use namespace::autoclean; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 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 | 1 | has 'product' => (is => 'rw', | |
| 71 | isa => 'Str', | ||
| 72 | default => 'BTC-USD', | ||
| 73 | ); | ||
| 74 | 1 | 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 | ▶ | my $self = shift; |
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
documented
| |||
| 89 | 1 | my $url = Finance::GDAX::API::URL->new; | |
| 90 | 1 | $url->debug($self->debug); | |
| 91 | 1 | $url->add('products'); | |
| 92 | 1 | $url->add($self->product); | |
| 93 | 1 | $url->add('ticker'); | |
| 94 | |||
| 95 | 1 | my $client = REST::Client->new; | |
| 96 | 1 | $client->GET($url->get); | |
| 97 | |||
| 98 | 1 | my $json = JSON->new; | |
| 99 | 1 | return $json->decode($client->responseContent); | |
| 100 | } | ||
| 101 | |||
| 102 | 1 | __PACKAGE__->meta->make_immutable; | |
| 103 | 1 | 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 | |||