line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::API::Bitfinex; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
43563
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
WWW::API::Bitfinex - API Btifinex |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Version 0.01 |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
+ HTTP / WebSocket ( Mojo::UserAgent ) |
22
|
|
|
|
|
|
|
- v2 |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
export BITFINEX_APIKEY='IDONTKNOW' |
25
|
|
|
|
|
|
|
export BITFINEX_APIPASS='HUHAAAAA' |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $B = Bitfinex->new(apikey => 'YOUKNOW' , apipass => 'WEKNOW'); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
1
|
|
254
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
9462
|
|
|
1
|
|
|
|
|
4
|
|
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
1
|
|
449
|
use Mojo::UserAgent; |
|
1
|
|
|
|
|
255612
|
|
|
1
|
|
|
|
|
8
|
|
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
1
|
|
171
|
use WWW::API::Bitfinex::Orders; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
use WWW::API::Bitfinex::Positions; |
37
|
|
|
|
|
|
|
use WWW::API::Bitfinex::Margin; |
38
|
|
|
|
|
|
|
use WWW::API::Bitfinex::Wallet; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
use JSON::XS; |
41
|
|
|
|
|
|
|
use Digest::SHA 'hmac_sha384_hex'; |
42
|
|
|
|
|
|
|
use MIME::Base64 'encode_base64'; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
use Data::Dumper; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
has debug => $ENV{'BITFINEX_DEBUG'} // 0; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
has apiver => 'v1'; |
49
|
|
|
|
|
|
|
has apikey => shift // $ENV{'BITFINEX_APIKEY'}; |
50
|
|
|
|
|
|
|
has apipass => shift // $ENV{'BITFINEX_APIPASS'}; |
51
|
|
|
|
|
|
|
has baseurl => 'https://api.bitfinex.com'; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
has UA => sub { Mojo::UserAgent->new; }; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
has Orders => sub { WWW::API::Bitfinex::Orders->new; }; |
56
|
|
|
|
|
|
|
has Positions => sub { WWW::API::Bitfinex::Positions->new; }; |
57
|
|
|
|
|
|
|
has Margin => sub { WWW::API::Bitfinex::Margin->new; }; |
58
|
|
|
|
|
|
|
has Wallet => sub { WWW::API::Bitfinex::Wallet->new; }; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 Auth call |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
sub Auth { |
66
|
|
|
|
|
|
|
my $self = shift; |
67
|
|
|
|
|
|
|
my $url = '/'.$self->apiver.'/'.shift; |
68
|
|
|
|
|
|
|
my $args = shift; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $req_url = $self->baseurl.$url; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
my $nonce = time()*1000; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $params = { |
75
|
|
|
|
|
|
|
nonce => $nonce.'.00', |
76
|
|
|
|
|
|
|
request => $url |
77
|
|
|
|
|
|
|
}; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
map { $params->{$_} = $args->{$_} } keys %{$args}; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
print Dumper encode_json($params) if $self->debug; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $payload = encode_base64(encode_json($params), ''); |
84
|
|
|
|
|
|
|
my $sha384 = hmac_sha384_hex($payload,$self->apipass); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
$self->UA->on(start => sub { |
87
|
|
|
|
|
|
|
my ($ua, $tx) = @_; |
88
|
|
|
|
|
|
|
$tx->req->headers->header('X-BFX-APIKEY' => $self->apikey ); |
89
|
|
|
|
|
|
|
$tx->req->headers->header('X-BFX-PAYLOAD' => $payload); |
90
|
|
|
|
|
|
|
$tx->req->headers->header('X-BFX-SIGNATURE' => $sha384); |
91
|
|
|
|
|
|
|
}); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$self->UA->post($req_url)->res->json; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 Public call |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
99
|
|
|
|
|
|
|
sub Public { |
100
|
|
|
|
|
|
|
my $self = shift; |
101
|
|
|
|
|
|
|
my $url = shift; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
$url = $self->baseurl.'/'.$self->apiver.'/'.$url; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$self->UA->get($url)->res->json; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub Required { |
109
|
|
|
|
|
|
|
my $self = shift; |
110
|
|
|
|
|
|
|
my $args = shift; |
111
|
|
|
|
|
|
|
my @chck = @_; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
for ( @chck ) { |
114
|
|
|
|
|
|
|
return { error => "Required: $_" } unless $args->{$_}; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=doc Public API |
119
|
|
|
|
|
|
|
=cut |
120
|
|
|
|
|
|
|
sub Funding { shift->Public('lends/'.shift); } |
121
|
|
|
|
|
|
|
sub Stats { shift->Public('stats/'.shift); } |
122
|
|
|
|
|
|
|
sub Symbols { shift->Public('symbols'); } |
123
|
|
|
|
|
|
|
sub SymbolsDetail { shift->Public('symbols_details'); } |
124
|
|
|
|
|
|
|
sub Ticker { shift->Public('ticker/'.shift); } |
125
|
|
|
|
|
|
|
sub Trades { shift->Public('trades/'.shift); } |
126
|
|
|
|
|
|
|
sub Orderbook { shift->Public('book/'.shift); } |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=doc Auth API |
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
sub Account { shift->Auth('account_infos'); } |
131
|
|
|
|
|
|
|
sub Summary { shift->Auth('summary'); } |
132
|
|
|
|
|
|
|
sub KeyInfo { shift->Auth('key_info'); } |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 AUTHOR |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Harun Delgado, C<< >> |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 BUGS |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
141
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
142
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 SUPPORT |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
perldoc WWW::API::Bitfinex |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
You can also look for information at: |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=over 4 |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
L |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
L |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item * CPAN Ratings |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
L |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=item * Search CPAN |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
L |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=back |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Copyright 2017 Harun Delgado. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
185
|
|
|
|
|
|
|
under the terms of the the Artistic License (2.0). You may obtain a |
186
|
|
|
|
|
|
|
copy of the full license at: |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
L |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified |
191
|
|
|
|
|
|
|
Versions is governed by this Artistic License. By using, modifying or |
192
|
|
|
|
|
|
|
distributing the Package, you accept this license. Do not use, modify, |
193
|
|
|
|
|
|
|
or distribute the Package, if you do not accept this license. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made |
196
|
|
|
|
|
|
|
by someone other than you, you are nevertheless required to ensure that |
197
|
|
|
|
|
|
|
your Modified Version complies with the requirements of this license. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service |
200
|
|
|
|
|
|
|
mark, tradename, or logo of the Copyright Holder. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge |
203
|
|
|
|
|
|
|
patent license to make, have made, use, offer to sell, sell, import and |
204
|
|
|
|
|
|
|
otherwise transfer the Package with respect to any patent claims |
205
|
|
|
|
|
|
|
licensable by the Copyright Holder that are necessarily infringed by the |
206
|
|
|
|
|
|
|
Package. If you institute patent litigation (including a cross-claim or |
207
|
|
|
|
|
|
|
counterclaim) against any party alleging that the Package constitutes |
208
|
|
|
|
|
|
|
direct or contributory patent infringement, then this Artistic License |
209
|
|
|
|
|
|
|
to you shall terminate on the date that such litigation is filed. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER |
212
|
|
|
|
|
|
|
AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. |
213
|
|
|
|
|
|
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
214
|
|
|
|
|
|
|
PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY |
215
|
|
|
|
|
|
|
YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR |
216
|
|
|
|
|
|
|
CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR |
217
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, |
218
|
|
|
|
|
|
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=cut |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
1; # End of WWW::API::Bitfinex |