lib/Finance/GDAX/API/Funding.pm

filter: Statementstmt 60.0% 24 / 40 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 75.0% 6 / 8 Podpod 100% 2 / 2 totaltotal 46.3% 32 / 69 CC 6 SCAR 25.6
CC
6
Cov
45%
repay
30.0
get
6.0
BEGIN
1.0
CRAP 12.9
« blib/lib/Finance/GDAX/API.pm ↑ Summary lib/Finance/GDAX/API/Report.pm »
1 package Finance::GDAX::API::Funding;
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 Finance::GDAX::API::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Finance::GDAX::API;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 extends 'Finance::GDAX::API';
11  
12 # List funding
13 1 has 'status' => (is => 'rw',
14 isa => 'Maybe[FundingStatus]',
15 );
16  
17 # Repay funding
18 1 has 'amount' => (is => 'rw',
19 isa => 'PositiveNum',
20 );
21 1 has 'currency' => (is => 'rw',
22 isa => 'Str',
23 );
24  
25 sub get {
26 0 ▶ my $self = shift;
Subroutine get: not called CC=2 SCAR=17.9
Pod documented
27 0 my $path = '/funding';
28 0 ▶ $path .= '?status=' . $self->status if $self->status;
Branch: 1 branch
BranchTrueFalseTotal
if $self->status 0 0 0
29 0 $self->path($path);
30 0 $self->method('GET');
31 0 return $self->send;
32 }
33  
34 sub repay {
35 0 ▶ my ($self, $amount, $currency) = @_;
Subroutine repay: not called CC=5 SCAR=34.0
Pod documented
36 0 ▶ $amount = $amount || $self->amount;
Condition0%0/3
$amount || $self->amount
l!l&&r!l&&!r
000
MC/DC0%0/2
$amount || $self->amount
$amount $self->amount
Truth table0%0/3
A || B
A= $amountB= $self->amount
ABresult
1X1
011
000
37 0 ▶ $currency = $currency || $self->currency;
Condition0%0/3
$currency || $self->currency
l!l&&r!l&&!r
000
MC/DC0%0/2
$currency || $self->currency
$currency $self->currency
Truth table0%0/3
A || B
A= $currencyB= $self->currency
ABresult
1X1
011
000
38 0 $self->amount($amount);
39 0 $self->currency($currency);
40 0 ▶ die 'repay must specify an amount and currency' unless ($amount && $currency);
Branch: 1 branch
BranchTrueFalseTotal
unless $amount and $currency 0 0 0
Condition0%0/3
$amount and $currency
!ll&&!rl&&r
000
MC/DC0%0/2
$amount and $currency
$amount $currency
Truth table0%0/3
A and B
A= $amountB= $currency
ABresult
0X0
100
111
41 0 $self->method('POST');
42 0 $self->body({ amount => $amount,
43 currency => $currency });
44 0 $self->path('/funding/repay');
45 0 return $self->send;
46 }
47  
48 1 __PACKAGE__->meta->make_immutable;
49 1 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  
« blib/lib/Finance/GDAX/API.pm ↑ Summary lib/Finance/GDAX/API/Report.pm »