line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::Bitcoin::Feed::Site::LakeBtc; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24668
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
5
|
1
|
|
|
1
|
|
408
|
use Mojo::Base 'Finance::Bitcoin::Feed::Site'; |
|
1
|
|
|
|
|
6771
|
|
|
1
|
|
|
|
|
6
|
|
6
|
1
|
|
|
1
|
|
624
|
use Mojo::UserAgent; |
|
1
|
|
|
|
|
226899
|
|
|
1
|
|
|
|
|
24
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has ws_url => 'wss://www.LakeBTC.com/websocket'; |
11
|
|
|
|
|
|
|
has 'ua'; |
12
|
|
|
|
|
|
|
has site => 'LAKEBTC'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub go { |
15
|
2
|
|
|
2
|
1
|
694
|
my $self = shift; |
16
|
2
|
|
|
|
|
11
|
$self->SUPER::go; |
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
|
|
15
|
$self->ua(Mojo::UserAgent->new()); |
19
|
2
|
|
|
|
|
79
|
$self->debug('connecting...', $self->ws_url); |
20
|
|
|
|
|
|
|
$self->ua->websocket( |
21
|
|
|
|
|
|
|
$self->ws_url => sub { |
22
|
2
|
|
|
2
|
|
207
|
my ($ua, $tx) = @_; |
23
|
2
|
|
|
|
|
6
|
$self->debug('connected!'); |
24
|
2
|
100
|
|
|
|
6
|
unless ($tx->is_websocket) { |
25
|
1
|
|
|
|
|
86
|
$self->error("Site " . $self->site . " WebSocket handshake failed!"); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# set timeout; |
28
|
1
|
|
|
|
|
8
|
$self->set_timeout; |
29
|
1
|
|
|
|
|
29
|
return; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
54
|
bless $tx, 'Mojo::Transaction::WebSocket::ForLakeBtc'; |
33
|
1
|
|
|
|
|
4
|
$tx->configure($self); |
34
|
2
|
|
|
|
|
34
|
}); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
package Mojo::Transaction::WebSocket::ForLakeBtc; # hidden from PAUSE |
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
1
|
|
940
|
use JSON; |
|
1
|
|
|
|
|
8899
|
|
|
1
|
|
|
|
|
5
|
|
41
|
1
|
|
|
1
|
|
133
|
use Mojo::Base 'Mojo::Transaction::WebSocket'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
42
|
1
|
|
|
1
|
|
169
|
use Scalar::Util qw(weaken); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
352
|
|
43
|
|
|
|
|
|
|
has 'owner'; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub configure { |
46
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
47
|
1
|
|
|
|
|
1
|
my $owner = shift; |
48
|
1
|
|
|
|
|
21
|
$self->owner($owner); |
49
|
1
|
|
|
|
|
9
|
weaken($self->{owner}); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# call parse when receive text event |
52
|
|
|
|
|
|
|
$self->on( |
53
|
|
|
|
|
|
|
json => sub { |
54
|
3
|
|
|
3
|
|
2788
|
my ($self, $message) = @_; |
55
|
3
|
|
|
|
|
4
|
$message = $message->[0]; |
56
|
3
|
|
|
|
|
4
|
my $command = shift @$message; |
57
|
3
|
|
|
|
|
9
|
$self->emit($command, $message); |
58
|
1
|
|
|
|
|
8
|
}); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
################################################ |
61
|
|
|
|
|
|
|
# setup events |
62
|
|
|
|
|
|
|
$self->on( |
63
|
|
|
|
|
|
|
subscribe => sub { |
64
|
1
|
|
|
1
|
|
9
|
my ($self, $channel) = @_; |
65
|
|
|
|
|
|
|
$self->on( |
66
|
|
|
|
|
|
|
'setup', |
67
|
|
|
|
|
|
|
sub { |
68
|
1
|
|
|
|
|
11
|
$self->send({json => ['websocket_rails.subscribe', {data => {channel => $channel}}]}); |
69
|
1
|
|
|
|
|
5
|
}); |
70
|
1
|
|
|
|
|
10
|
}); |
71
|
1
|
|
|
|
|
10
|
$self->emit('subscribe', 'ticker'); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
######################################## |
74
|
|
|
|
|
|
|
# events from server |
75
|
|
|
|
|
|
|
$self->on( |
76
|
|
|
|
|
|
|
'client_connected', |
77
|
|
|
|
|
|
|
sub { |
78
|
1
|
|
|
1
|
|
5
|
my $self = shift; |
79
|
1
|
|
|
|
|
3
|
$self->emit('setup'); |
80
|
1
|
|
|
|
|
10
|
}); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
$self->on( |
83
|
|
|
|
|
|
|
'websocket_rails.ping', |
84
|
|
|
|
|
|
|
sub { |
85
|
1
|
|
|
1
|
|
18
|
shift->send({json => ['websocket_rails.pong', undef, undef]}); |
86
|
1
|
|
|
|
|
8
|
}); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
$self->on( |
89
|
|
|
|
|
|
|
'update', |
90
|
|
|
|
|
|
|
sub { |
91
|
1
|
|
|
1
|
|
5
|
my ($self, $data) = @_; |
92
|
1
|
|
|
|
|
3
|
$data = $data->[0]{data}; |
93
|
1
|
|
|
|
|
6
|
for my $k (sort keys %$data) { |
94
|
2
|
|
|
|
|
72
|
$self->owner->emit( |
95
|
|
|
|
|
|
|
'data_out', |
96
|
|
|
|
|
|
|
0, # no timestamp |
97
|
|
|
|
|
|
|
uc("${k}BTC"), |
98
|
|
|
|
|
|
|
$data->{$k}{last}, |
99
|
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
1
|
|
|
|
|
9
|
}); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__ |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 NAME |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Finance::Bitcoin::Feed::Site::Lakebtc -- the class that connect and fetch the bitcoin price data from site lakebtc |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 SYNOPSIS |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
use Finance::Bitcoin::Feed::Site::Lakebtc; |
116
|
|
|
|
|
|
|
use AnyEvent; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
my $obj = Finance::Bitcoin::Feed::Site::Lakebtc->new(); |
119
|
|
|
|
|
|
|
# listen on the event 'output' to get the adata |
120
|
|
|
|
|
|
|
$obj->on('output', sub { shift; say @_ }); |
121
|
|
|
|
|
|
|
$obj->go(); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# dont forget this |
124
|
|
|
|
|
|
|
AnyEvent->condvar->recv; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 DESCRIPTION |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Connect to site BitStamp by protocol socket.io v2.2.2 and fetch the bitcoin price data. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 EVENTS |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This class inherits all events from L<Finance::Bitcoin::Feed::Site> and add some new ones. |
133
|
|
|
|
|
|
|
The most important event is 'output'. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 output |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
It will be emit by its parent class when print out the data. You can listen on this event to get the output. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 subscribe |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
It will subscribe channel from the source site. You can subscribe more channels in the method L</configure> |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 SEE ALSO |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
L<Finance::Bitcoin::Feed::Site> |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
L<lakebtc api|https://www.lakebtc.com/s/api> |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
L<Mojo::UserAgent> |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 BUGS |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
This module doesn't print the timestamp because the data source no timestamp. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 AUTHOR |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Chylli C<< <chylli@binary.com> >> |
158
|
|
|
|
|
|
|
|