line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::Bitcoin::Feed::Site::LakeBtc::Socket; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
497
|
use JSON; |
|
1
|
|
|
|
|
9198
|
|
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
523
|
use Mojo::Base 'Mojo::Transaction::WebSocket'; |
|
1
|
|
|
|
|
5885
|
|
|
1
|
|
|
|
|
6
|
|
5
|
1
|
|
|
1
|
|
97037
|
use Scalar::Util qw(weaken); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
276
|
|
6
|
|
|
|
|
|
|
has 'owner'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub configure { |
9
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
10
|
1
|
|
|
|
|
1
|
my $owner = shift; |
11
|
1
|
|
|
|
|
4
|
$self->owner($owner); |
12
|
1
|
|
|
|
|
6
|
weaken($self->{owner}); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# call parse when receive text event |
15
|
|
|
|
|
|
|
$self->on( |
16
|
|
|
|
|
|
|
json => sub { |
17
|
3
|
|
|
3
|
|
2569
|
my ($self, $message) = @_; |
18
|
3
|
|
|
|
|
4
|
$message = $message->[0]; |
19
|
3
|
|
|
|
|
1
|
my $command = shift @$message; |
20
|
3
|
|
|
|
|
12
|
$self->emit($command, $message); |
21
|
1
|
|
|
|
|
6
|
}); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
################################################ |
24
|
|
|
|
|
|
|
# setup events |
25
|
|
|
|
|
|
|
$self->on( |
26
|
|
|
|
|
|
|
subscribe => sub { |
27
|
1
|
|
|
1
|
|
7
|
my ($self, $channel) = @_; |
28
|
|
|
|
|
|
|
$self->on( |
29
|
|
|
|
|
|
|
'setup', |
30
|
|
|
|
|
|
|
sub { |
31
|
1
|
|
|
|
|
8
|
$self->send({json => ['websocket_rails.subscribe', {data => {channel => $channel}}]}); |
32
|
1
|
|
|
|
|
5
|
}); |
33
|
1
|
|
|
|
|
9
|
}); |
34
|
1
|
|
|
|
|
8
|
$self->emit('subscribe', 'ticker'); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
######################################## |
37
|
|
|
|
|
|
|
# events from server |
38
|
|
|
|
|
|
|
$self->on( |
39
|
|
|
|
|
|
|
'client_connected', |
40
|
|
|
|
|
|
|
sub { |
41
|
1
|
|
|
1
|
|
4
|
my $self = shift; |
42
|
1
|
|
|
|
|
3
|
$self->emit('setup'); |
43
|
1
|
|
|
|
|
8
|
}); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
$self->on( |
46
|
|
|
|
|
|
|
'websocket_rails.ping', |
47
|
|
|
|
|
|
|
sub { |
48
|
1
|
|
|
1
|
|
11
|
shift->send({json => ['websocket_rails.pong', undef, undef]}); |
49
|
1
|
|
|
|
|
6
|
}); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$self->on( |
52
|
|
|
|
|
|
|
'update', |
53
|
|
|
|
|
|
|
sub { |
54
|
1
|
|
|
1
|
|
5
|
my ($self, $data) = @_; |
55
|
1
|
|
|
|
|
2
|
$data = $data->[0]{data}; |
56
|
1
|
|
|
|
|
5
|
for my $k (sort keys %$data) { |
57
|
2
|
|
|
|
|
6
|
$self->owner->emit( |
58
|
|
|
|
|
|
|
'data_out', |
59
|
|
|
|
|
|
|
0, # no timestamp |
60
|
|
|
|
|
|
|
uc("${k}BTC"), |
61
|
|
|
|
|
|
|
$data->{$k}{last}, |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
1
|
|
|
|
|
6
|
}); |
66
|
1
|
|
|
|
|
5
|
return; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |