File Coverage

lib/Finance/GDAX/API/MarginTransfer.pm
Criterion Covered Total %
statement 20 24 83.3
branch 0 2 0.0
condition 2 9 22.2
subroutine 7 7 100.0
pod 1 1 100.0
total 30 43 69.7


line stmt bran cond sub pod time code
1             package Finance::GDAX::API::MarginTransfer;
2             our $VERSION = '0.01';
3 1     1   19497 use 5.20.0;
  1         3  
4 1     1   5 use warnings;
  1         1  
  1         19  
5 1     1   420 use Moose;
  1         407972  
  1         5  
6 1     1   6859 use Finance::GDAX::API::TypeConstraints;
  1         3  
  1         39  
7 1     1   389 use Finance::GDAX::API;
  1         3  
  1         35  
8 1     1   9 use namespace::autoclean;
  1         2  
  1         8  
9              
10             extends 'Finance::GDAX::API';
11              
12             has 'margin_profile_id' => (is => 'rw',
13             isa => 'Str',
14             );
15             has 'type' => (is => 'rw',
16             isa => 'MarginTransferType',
17             );
18             has 'amount' => (is => 'rw',
19             isa => 'PositiveNum',
20             );
21             has 'currency' => (is => 'rw',
22             isa => 'Str',
23             );
24              
25             sub initiate {
26 1     1 1 143 my $self = shift;
27 1 0 33     50 unless ($self->margin_profile_id &&
      33        
      0        
28             $self->type &&
29             $self->amount &&
30             $self->currency) {
31 1         10 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             __PACKAGE__->meta->make_immutable;
44             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