File Coverage

lib/Finance/GDAX/API/Account.pm
Criterion Covered Total %
statement 14 33 42.4
branch 0 6 0.0
condition n/a
subroutine 5 9 55.5
pod 4 4 100.0
total 23 52 44.2


line stmt bran cond sub pod time code
1             package Finance::GDAX::API::Account;
2             our $VERSION = '0.02';
3 1     1   27265 use 5.20.0;
  1         5  
4 1     1   9 use warnings;
  1         2  
  1         38  
5 1     1   613 use Moose;
  1         458989  
  1         6  
6 1     1   6862 use Finance::GDAX::API;
  1         3  
  1         35  
7 1     1   9 use namespace::autoclean;
  1         2  
  1         8  
8              
9             extends 'Finance::GDAX::API';
10              
11             sub get_all {
12 0     0 1   my $self = shift;
13 0           $self->method('GET');
14 0           $self->path('/accounts');
15 0           return $self->send;
16             }
17              
18             sub get {
19 0     0 1   my ($self, $account_id) = @_;
20 0 0         die 'Account ID is required' unless $account_id;
21 0           $self->method('GET');
22 0           $self->path("/accounts/$account_id");
23 0           return $self->send;
24             }
25              
26             sub history {
27 0     0 1   my ($self, $account_id) = @_;
28 0 0         die 'Account ID is required' unless $account_id;
29 0           $self->method('GET');
30 0           $self->path("/accounts/$account_id/ledger");
31 0           return $self->send;
32             }
33              
34             sub holds {
35 0     0 1   my ($self, $account_id) = @_;
36 0 0         die 'Account ID is required' unless $account_id;
37 0           $self->method('GET');
38 0           $self->path("/accounts/$account_id/holds");
39 0           return $self->send;
40             }
41              
42             __PACKAGE__->meta->make_immutable;
43             1;
44              
45             =head1 NAME
46              
47             Finance::GDAX::API::Account - Work with GDAX Accounts
48              
49             =head1 SYNOPSIS
50              
51             use Finance::GDAX::API::Account;
52              
53             $account = Finance::GDAX::API::Account->new(
54             key => 'wowihefoiwhoihw',
55             secret => 'woihoip2hf23908hf32hf2h',
56             passphrase => 'woiefhvbno3iurbnv9p4h49h');
57              
58             # List all accounts
59             $accounts = $account->get_all;
60             if ($account->error) {
61             die 'There was an error '.$account->error;
62             }
63             foreach (@$accounts) {
64             print $$_{currency}." = ".$$_{balance};
65             }
66              
67             # List a single account
68             $info = $account->get("wiejfwef-237897-wefhwe-wef");
69             say 'Balance is ' . $$info{balance} . $$info{currency};
70              
71             =head1 DESCRIPTION
72              
73             Creates a GDAX account object to examine accounts.
74              
75             See Finance::GDAX::API for details on API key requirements that
76             need to be passed in.
77              
78             The HTTP response code can be accessed via the "response_code"
79             attribute, and if the request resulted in a response code greater than
80             or equal to 400, then the "error" attribute will be set to the error
81             message returned by the GDAX servers.
82              
83              
84             =head1 METHODS
85              
86             =head2 C<get_all>
87              
88             Returns an array of hashes, with each hash representing account
89             details. According to the GDAX API, currently these hashes will
90             contain the following keys and data:
91              
92             The following represents the data structure from their current API
93             docs:
94              
95             [
96             {
97             "id": "71452118-efc7-4cc4-8780-a5e22d4baa53",
98             "currency": "BTC",
99             "balance": "0.0000000000000000",
100             "available": "0.0000000000000000",
101             "hold": "0.0000000000000000",
102             "profile_id": "75da88c5-05bf-4f54-bc85-5c775bd68254"
103             },
104             {
105             "id": "e316cb9a-0808-4fd7-8914-97829c1925de",
106             "currency": "USD",
107             "balance": "80.2301373066930000",
108             "available": "79.2266348066930000",
109             "hold": "1.0035025000000000",
110             "profile_id": "75da88c5-05bf-4f54-bc85-5c775bd68254"
111             }
112             ]
113              
114             id Account ID
115             balance total funds in the account
116             holds funds on hold (not available for use)
117             available funds available to withdraw* or trade
118             margin_enabled [margin] true if the account belongs to margin profile
119             funded_amount [margin] amount of outstanding funds currently credited to
120             the account
121             default_amount [margin] amount defaulted on due to not being able to pay
122             back funding
123              
124             However, this does not appear to be exactly what they are sending now.
125              
126             =head2 C<get> $account_id
127              
128             The get method requires passing an account id and returns a hash of
129             the account information. Currently the GDAX API docs say they are:
130              
131             The following represents the data structure from their current API
132             docs:
133              
134             {
135             "id": "a1b2c3d4",
136             "balance": "1.100",
137             "holds": "0.100",
138             "available": "1.00",
139             "currency": "USD"
140             }
141              
142             id Account ID
143             balance total funds in the account
144             holds funds on hold (not available for use)
145             available funds available to withdraw* or trade
146             margin_enabled [margin] true if the account belongs to margin profile
147             funded_amount [margin] amount of outstanding funds currently credited to
148             the account
149             default_amount [margin] amount defaulted on due to not being able to pay
150             back funding
151              
152             =head2 C<history> $account_id
153              
154             The history method returns an array of hashes representing the history
155             of transactions on the specified account_id.
156              
157             The limit is 100 transactions - no paging has been implemented in this
158             API, through the GDAX API does support paging apparently.
159              
160             The following represents the data structure from their current API
161             docs:
162              
163             [
164             {
165             "id": "100",
166             "created_at": "2014-11-07T08:19:27.028459Z",
167             "amount": "0.001",
168             "balance": "239.669",
169             "type": "fee",
170             "details": {
171             "order_id": "d50ec984-77a8-460a-b958-66f114b0de9b",
172             "trade_id": "74",
173             "product_id": "BTC-USD"
174             }
175             }
176             ]
177              
178             With different "type"'s meaning different "details" -- and those types
179             are:
180              
181             transfer Funds moved to/from Coinbase to GDAX
182             match Funds moved as a result of a trade
183             fee Fee as a result of a trade
184             rebate Fee rebate as per our fee schedule
185              
186             =head2 C<holds> $account_id
187              
188             The holds method returns an array of hashes representing the holds placed on the $account_id account, which happen due to active orders or pending withdrawls.
189              
190             The following represents the data structure from their current API
191             docs:
192              
193             [
194             {
195             "id": "82dcd140-c3c7-4507-8de4-2c529cd1a28f",
196             "account_id": "e0b3f39a-183d-453e-b754-0c13e5bab0b3",
197             "created_at": "2014-11-06T10:34:47.123456Z",
198             "updated_at": "2014-11-06T10:40:47.123456Z",
199             "amount": "4.23",
200             "type": "order",
201             "ref": "0a205de4-dd35-4370-a285-fe8fc375a273",
202             }
203             ]
204              
205             =cut
206              
207             =head1 AUTHOR
208              
209             Mark Rushing <mark@orbislumen.net>
210              
211             =head1 COPYRIGHT AND LICENSE
212              
213             This software is copyright (c) 2017 by Home Grown Systems, SPC.
214              
215             This is free software; you can redistribute it and/or modify it under
216             the same terms as the Perl 5 programming language system itself.
217              
218             =cut
219              
220