line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::GDAX::API::Funding; |
2
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
3
|
1
|
|
|
1
|
|
19327
|
use 5.20.0; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
5
|
1
|
|
|
1
|
|
412
|
use Moose; |
|
1
|
|
|
|
|
491738
|
|
|
1
|
|
|
|
|
9
|
|
6
|
1
|
|
|
1
|
|
8954
|
use Finance::GDAX::API::TypeConstraints; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
89
|
|
7
|
1
|
|
|
1
|
|
687
|
use Finance::GDAX::API; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
44
|
|
8
|
1
|
|
|
1
|
|
10
|
use namespace::autoclean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
12
|
|
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
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
27
|
0
|
|
|
|
|
|
my $path = '/funding'; |
28
|
0
|
0
|
|
|
|
|
$path .= '?status=' . $self->status if $self->status; |
29
|
0
|
|
|
|
|
|
$self->path($path); |
30
|
0
|
|
|
|
|
|
$self->method('GET'); |
31
|
0
|
|
|
|
|
|
return $self->send; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub repay { |
35
|
0
|
|
|
0
|
1
|
|
my ($self, $amount, $currency) = @_; |
36
|
0
|
|
0
|
|
|
|
$amount = $amount || $self->amount; |
37
|
0
|
|
0
|
|
|
|
$currency = $currency || $self->currency; |
38
|
0
|
|
|
|
|
|
$self->amount($amount); |
39
|
0
|
|
|
|
|
|
$self->currency($currency); |
40
|
0
|
0
|
0
|
|
|
|
die 'repay must specify an amount and currency' unless ($amount && $currency); |
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
|
|
|
|
|
|
|
__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
|
|
|
|
|
|
|
|