lib/Finance/GDAX/API/MarginTransfer.pm

filter: Statementstmt 87.5% 28 / 32 Branchbran 0.0% 0 / 2 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 70.9% 39 / 55 CC 5 SCAR 18.2
CC
5
Cov
72%
initiate
12.4
BEGIN
1.0
BEGIN
1.0
CRAP 6.2
« lib/Finance/GDAX/API/Withdrawl.pm ↑ Summary lib/Finance/GDAX/API/Deposit.pm »
1 package Finance::GDAX::API::MarginTransfer;
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 1 has 'margin_profile_id' => (is => 'rw',
13 isa => 'Str',
14 );
15 1 has 'type' => (is => 'rw',
16 isa => 'MarginTransferType',
17 );
18 1 has 'amount' => (is => 'rw',
19 isa => 'PositiveNum',
20 );
21 1 has 'currency' => (is => 'rw',
22 isa => 'Str',
23 );
24  
25 sub initiate {
26 1 ▶ my $self = shift;
Subroutine initiate: called CC=5 SCAR=25.2
Pod documented
27 1 ▶ unless ($self->margin_profile_id &&
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->margin_profile_id and $self->type and $self->amount and $self->currency) 0 0 0
Condition33%3/9
$self->margin_profile_id and $self->type and $self->amount and $self->currency
!ll&&!rl&&r
100
$self->margin_profile_id and $self->type and $self->amount
!ll&&!rl&&r
100
$self->margin_profile_id and $self->type
!ll&&!rl&&r
100
MC/DC0%0/4
$self->margin_profile_id and $self->type and $self->amount and $self->currency
$self->margin_profile_id $self->type $self->amount $self->currency
Truth table20%1/5
A and B and C and D
A= $self->margin_profile_idB= $self->typeC= $self->amountD= $self->currency
ABCDresult
0XXX0
10XX0
110X0
11100
11111
28 $self->type &&
29 $self->amount &&
30 $self->currency) {
31 1 die 'Margin transfers need all attributes set';
32 }
33 0 $self->path('/profiles/margin-transfer');
34 0 $self->method('POST');
35 0 $self->body({ amount => $self->amount,
36 currency => $self->currency,
37 type => $self->type,
38 margin_profile_id => $self->margin_profile_id,
39 });
40 0 return $self->send;
41 }
42  
43 1 __PACKAGE__->meta->make_immutable;
44 1 1;
45  
46 =head1 NAME
47  
48 Finance::GDAX::API::MarginTransfer - Transfer funds between margin and
49 standard GDAX profiles
50  
51 =head1 SYNOPSIS
52  
53 use Finance::GDAX::API::MarginTransfer;
54  
55 $xfer = Finance::GDAX::API::MarginTransfer->new(
56 type => 'withdrawl',
57 currency => 'USD',
58 amount => '250.00');
59  
60 $xfer->margin_profile_id('kwji-wefwe-ewrgeurg-wef');
61  
62 $response = $xfer->initiate;
63  
64 =head2 DESCRIPTION
65  
66 Used to transfer funds between the GDAX standard/default profile and
67 the margin account. All attributes are required to be set before
68 calling the "initiate" method.
69  
70 From the GDAX API:
71  
72 =over
73  
74 Transfer funds between your standard/default profile and a margin
75 profile. A deposit will transfer funds from the default profile into
76 the margin profile. A withdraw will transfer funds from the margin
77 profile to the default profile. Withdraws will fail if they would set
78 your margin ratio below the initial margin ratio requirement.
79  
80 =back
81  
82 =head1 ATTRIBUTES
83  
84 =head2 C<margin_profile_id> $string
85  
86 The id of the margin profile you'd like to deposit to or withdraw from.
87  
88 =head2 C<type> $margin_transfer_type
89  
90 "deposit" or "withdraw".
91  
92 Deposit transfers out from the default profile, into the margin
93 profile.
94  
95 Withdraw transfers out of the margin account and into the default
96 profile.
97  
98 =head2 C<amount> $number
99  
100 The amount to be transferred.
101  
102 =head2 C<currency> $currency_string
103  
104 The currency of the amount -- for example "USD".
105  
106 =head1 METHODS
107  
108 =head2 C<initiate>
109  
110 All attributed must be set before calling this method. The return
111 value is a hash that will describe the result of the transfer.
112  
113 From the current GDAX API documentation, this is how that returned hash is
114 keyed:
115  
116 {
117 "created_at": "2017-01-25T19:06:23.415126Z",
118 "id": "80bc6b74-8b1f-4c60-a089-c61f9810d4ab",
119 "user_id": "521c20b3d4ab09621f000011",
120 "profile_id": "cda95996-ac59-45a3-a42e-30daeb061867",
121 "margin_profile_id": "45fa9e3b-00ba-4631-b907-8a98cbdf21be",
122 "type": "deposit",
123 "amount": "2",
124 "currency": "USD",
125 "account_id": "23035fc7-0707-4b59-b0d2-95d0c035f8f5",
126 "margin_account_id": "e1d9862c-a259-4e83-96cd-376352a9d24d",
127 "margin_product_id": "BTC-USD",
128 "status": "completed",
129 "nonce": 25
130 }
131  
132 =cut
133  
134  
135 =head1 AUTHOR
136  
137 Mark Rushing <mark@orbislumen.net>
138  
139 =head1 COPYRIGHT AND LICENSE
140  
141 This software is copyright (c) 2017 by Home Grown Systems, SPC.
142  
143 This is free software; you can redistribute it and/or modify it under
144 the same terms as the Perl 5 programming language system itself.
145  
146 =cut
147  
« lib/Finance/GDAX/API/Withdrawl.pm ↑ Summary lib/Finance/GDAX/API/Deposit.pm »