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

filter: Statementstmt 0.0% 0 / 41 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 9 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 64 CC 3 SCAR 12.8
CC
3
Cov
0%
get
6.0
repay
6.0
BEGIN
2.0
CRAP 3.6
1 package Finance::GDAX::API::Funding;
2 our $VERSION = '0.01';
3 use 5.20.0;
4 use warnings;
5 use Moose;
6 use Finance::GDAX::API::TypeConstraints;
7 use Finance::GDAX::API;
8 use namespace::autoclean;
9  
10 extends 'Finance::GDAX::API';
11  
12 # List funding
13 has 'status' => (is => 'rw',
14 isa => 'Maybe[FundingStatus]',
15 );
16  
17 # Repay funding
18 has 'amount' => (is => 'rw',
19 isa => 'PositiveNum',
20 );
21 has 'currency' => (is => 'rw',
22 isa => 'Str',
23 );
24  
25 sub get {
26 my $self = shift;
27 my $path = '/funding';
28 $path .= '?status=' . $self->status if $self->status;
29 $self->path($path);
30 $self->method('GET');
31 return $self->send;
32 }
33  
34 sub repay {
35 my ($self, $amount, $currency) = @_;
36 $amount = $amount || $self->amount;
37 $currency = $currency || $self->currency;
38 $self->amount($amount);
39 $self->currency($currency);
40 die 'repay must specify an amount and currency' unless ($amount && $currency);
41 $self->method('POST');
42 $self->body({ amount => $amount,
43 currency => $currency });
44 $self->path('/funding/repay');
45 return $self->send;
46 }
47  
48 __PACKAGE__->meta->make_immutable;
49 1;
50  
51 =head1 NAME
52  
53 Finance::GDAX::API::Funding - List GDAX margin funding records
54  
55 =head1 SYNOPSIS
56  
57 use Finance::GDAX::API::Funding;
58  
59 $funding = Finance::GDAX::API::Funding->new;
60 $records = $funding->get;
61  
62 # To limit records based on current status
63 $funding->status('settled');
64 $records = $funding->get;
65  
66 # To repay some margin funding
67 $funding->repay('255.45', 'USD');
68  
69 =head2 DESCRIPTION
70  
71 Returns an array of funding records from GDAX for orders placed with a
72 margin profile. Also repays margin funding.
73  
74 From the GDAX API:
75  
76 Every order placed with a margin profile that draws funding will
77 create a funding record.
78  
79 [
80 {
81 "id": "b93d26cd-7193-4c8d-bfcc-446b2fe18f71",
82 "order_id": "b93d26cd-7193-4c8d-bfcc-446b2fe18f71",
83 "profile_id": "d881e5a6-58eb-47cd-b8e2-8d9f2e3ec6f6",
84 "amount": "1057.6519956381537500",
85 "status": "settled",
86 "created_at": "2017-03-17T23:46:16.663397Z",
87 "currency": "USD",
88 "repaid_amount": "1057.6519956381537500",
89 "default_amount": "0",
90 "repaid_default": false
91 },
92 {
93 "id": "280c0a56-f2fa-4d3b-a199-92df76fff5cd",
94 "order_id": "280c0a56-f2fa-4d3b-a199-92df76fff5cd",
95 "profile_id": "d881e5a6-58eb-47cd-b8e2-8d9f2e3ec6f6",
96 "amount": "545.2400000000000000",
97 "status": "outstanding",
98 "created_at": "2017-03-18T00:34:34.270484Z",
99 "currency": "USD",
100 "repaid_amount": "532.7580047716682500"
101 },
102 {
103 "id": "d6ec039a-00eb-4bec-a3e1-f5c6a97c4afc",
104 "order_id": "d6ec039a-00eb-4bec-a3e1-f5c6a97c4afc",
105 "profile_id": "d881e5a6-58eb-47cd-b8e2-8d9f2e3ec6f6",
106 "amount": "9.9999999958500000",
107 "status": "outstanding",
108 "created_at": "2017-03-19T23:16:11.615181Z",
109 "currency": "USD",
110 "repaid_amount": "0"
111 }
112 ]
113  
114 =head1 ATTRIBUTES
115  
116 =head2 C<status> $string
117  
118 Limit the records returned to those records of status
119 $status.
120  
121 Currently the GDAX API states these status must be "outstanding",
122 "settled" or "rejected".
123  
124 =head2 C<amount> $number
125  
126 The amount to be repaid to margin.
127  
128 =head2 C<currency> $currency_string
129  
130 The currency of the amount -- for example "USD".
131  
132 You must specify currency and amount when calling the repay method.
133  
134 =head1 METHODS
135  
136 =head2 C<get>
137  
138 Returns an array of funding records from GDAX.
139  
140 =head2 C<repay> [$amount, $currency]
141  
142 Repays the margin, from the oldest funding records first.
143  
144 Specifying the optional ordered parameters $amount and $currency on
145 the method call will override any attribute values set for amount and
146 currency.
147  
148 =cut
149  
150  
151 =head1 AUTHOR
152  
153 Mark Rushing <mark@orbislumen.net>
154  
155 =head1 COPYRIGHT AND LICENSE
156  
157 This software is copyright (c) 2017 by Home Grown Systems, SPC.
158  
159 This is free software; you can redistribute it and/or modify it under
160 the same terms as the Perl 5 programming language system itself.
161  
162 =cut
163