line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::Bitcoin::Feed::Site::BitStamp; |
2
|
1
|
|
|
1
|
|
26546
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
3
|
1
|
|
|
1
|
|
412
|
use Mojo::Base 'Finance::Bitcoin::Feed::Site'; |
|
1
|
|
|
|
|
6765
|
|
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has 'socket'; |
8
|
|
|
|
|
|
|
has 'site' => 'BITSTAMP'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub go { |
11
|
1
|
|
|
1
|
1
|
381
|
my $self = shift; |
12
|
1
|
|
|
|
|
7
|
$self->SUPER::go; |
13
|
1
|
|
|
|
|
8
|
$self->debug('connecting...'); |
14
|
1
|
|
|
|
|
4
|
$self->socket(Finance::Bitcoin::Feed::BitStamp::Socket->new($self)); |
15
|
1
|
|
|
|
|
36
|
$self->socket->go; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package Finance::Bitcoin::Feed::BitStamp::Socket; |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
252
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
21
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
22
|
1
|
|
|
1
|
|
487
|
use parent qw(Finance::Bitcoin::Feed::Pusher); |
|
1
|
|
|
|
|
243
|
|
|
1
|
|
|
|
|
4
|
|
23
|
1
|
|
|
1
|
|
57
|
use Scalar::Util qw(weaken); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
167
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub new { |
26
|
1
|
|
|
1
|
|
19
|
my $self = shift->SUPER::new(channels => [qw/live_trades/]); |
27
|
1
|
|
|
|
|
3
|
$self->{owner} = shift; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
#weaken it to prevent from crossing reference |
30
|
1
|
|
|
|
|
16
|
weaken($self->{owner}); |
31
|
1
|
|
|
|
|
2
|
return $self; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub trade { |
35
|
1
|
|
|
1
|
0
|
1417
|
my $self = shift; |
36
|
1
|
|
|
|
|
2
|
my $data = shift; |
37
|
1
|
|
|
|
|
8
|
$self->{owner}->emit('data_out', 0, "BTCUSD", $data->{price}); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub go { |
41
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
42
|
0
|
|
|
|
|
|
$self->setup; |
43
|
0
|
|
|
|
|
|
$self->handle; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
__END__ |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 NAME |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Finance::Bitcoin::Feed::Site::BitStamp -- the class that connect and fetch the bitcoin price data from site bitstamp |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 SYNOPSIS |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
use Finance::Bitcoin::Feed::Site::BitStamp; |
58
|
|
|
|
|
|
|
use AnyEvent; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $obj = Finance::Bitcoin::Feed::Site::BitStamp->new(); |
61
|
|
|
|
|
|
|
# listen on the event 'output' to get the adata |
62
|
|
|
|
|
|
|
$obj->on('output', sub { shift; say @_ }); |
63
|
|
|
|
|
|
|
$obj->go(); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# dont forget this |
66
|
|
|
|
|
|
|
AnyEvent->condvar->recv; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 DESCRIPTION |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Connect to site BitStamp by protocol Pusher and fetch the bitcoin price data. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 EVENTS |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
This class inherits all events from L<Finance::Bitcoin::Feed::Site>. |
75
|
|
|
|
|
|
|
The most important event is 'output'. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 output |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
It will be emit by its parent class when print out the data. You can listen on this event to get the output. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 SEE ALSO |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
L<Finance::Bitcoin::Feed::Site> |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
L<Finance::BitStamp::Socket> |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
L<bitstamp|https://www.bitstamp.net/websocket/> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 AUTHOR |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Chylli C<< <chylli@binary.com> >> |
93
|
|
|
|
|
|
|
|