File Coverage

blib/lib/Finance/Bitcoin/Feed/Site/LakeBtc.pm
Criterion Covered Total %
statement 29 29 100.0
branch 2 2 100.0
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 39 39 100.0


line stmt bran cond sub pod time code
1             package Finance::Bitcoin::Feed::Site::LakeBtc;
2              
3 1     1   29808 use strict;
  1         1  
  1         26  
4 1     1   3 use warnings;
  1         2  
  1         23  
5 1     1   286 use Finance::Bitcoin::Feed::Site::LakeBtc::Socket;
  1         2  
  1         9  
6 1     1   24 use Mojo::Base 'Finance::Bitcoin::Feed::Site';
  1         1  
  1         4  
7 1     1   573 use Mojo::UserAgent;
  1         76891  
  1         9  
8              
9             our $VERSION = '0.05';
10              
11             has ws_url => 'wss://www.LakeBTC.com/websocket';
12             has 'ua';
13             has site => 'LAKEBTC';
14              
15             sub go {
16 2     2 1 671 my $self = shift;
17 2         10 $self->SUPER::go;
18              
19 2         7 $self->ua(Mojo::UserAgent->new());
20 2         12 $self->debug('connecting...', $self->ws_url);
21             $self->ua->websocket(
22             $self->ws_url => sub {
23 2     2   140 my ($ua, $tx) = @_;
24 2         4 $self->debug('connected!');
25 2 100       6 unless ($tx->is_websocket) {
26 1         48 $self->error("Site " . $self->site . " WebSocket handshake failed!");
27              
28             # set timeout;
29 1         8 $self->set_timeout;
30 1         2 return;
31             }
32              
33 1         45 bless $tx, 'Finance::Bitcoin::Feed::Site::LakeBtc::Socket';
34 1         5 $tx->configure($self);
35 2         5 });
36 2         8 return;
37             }
38              
39             1;
40              
41             __END__
42              
43             =head1 NAME
44              
45             Finance::Bitcoin::Feed::Site::Lakebtc -- the class that connect and fetch the bitcoin price data from site lakebtc
46              
47             =head1 SYNOPSIS
48              
49             use Finance::Bitcoin::Feed::Site::Lakebtc;
50             use AnyEvent;
51              
52             my $obj = Finance::Bitcoin::Feed::Site::Lakebtc->new();
53             # listen on the event 'output' to get the adata
54             $obj->on('output', sub { shift; say @_ });
55             $obj->go();
56              
57             # dont forget this
58             AnyEvent->condvar->recv;
59              
60             =head1 DESCRIPTION
61              
62             Connect to site BitStamp by protocol socket.io v2.2.2 and fetch the bitcoin price data.
63              
64             =head1 EVENTS
65              
66             This class inherits all events from L<Finance::Bitcoin::Feed::Site> and add some new ones.
67             The most important event is 'output'.
68              
69             =head2 output
70              
71             It will be emit by its parent class when print out the data. You can listen on this event to get the output.
72              
73             =head2 subscribe
74              
75             It will subscribe channel from the source site. You can subscribe more channels in the method L</configure>
76              
77             =head1 SEE ALSO
78              
79             L<Finance::Bitcoin::Feed::Site>
80              
81             L<lakebtc api|https://www.lakebtc.com/s/api>
82              
83             L<Mojo::UserAgent>
84              
85             =head1 BUGS
86              
87             This module doesn't print the timestamp because the data source no timestamp.
88              
89             =head1 AUTHOR
90              
91             Chylli C<< <chylli@binary.com> >>
92