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   20254 use strict;
  1         1  
  1         25  
4 1     1   2 use warnings;
  1         1  
  1         21  
5 1     1   298 use Finance::Bitcoin::Feed::Site::LakeBtc::Socket;
  1         2  
  1         8  
6 1     1   25 use Mojo::Base 'Finance::Bitcoin::Feed::Site';
  1         1  
  1         4  
7 1     1   522 use Mojo::UserAgent;
  1         78806  
  1         7  
8              
9             our $VERSION = '0.04';
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 649 my $self = shift;
17 2         8 $self->SUPER::go;
18              
19 2         6 $self->ua(Mojo::UserAgent->new());
20 2         11 $self->debug('connecting...', $self->ws_url);
21             $self->ua->websocket(
22             $self->ws_url => sub {
23 2     2   103 my ($ua, $tx) = @_;
24 2         5 $self->debug('connected!');
25 2 100       5 unless ($tx->is_websocket) {
26 1         50 $self->error("Site " . $self->site . " WebSocket handshake failed!");
27              
28             # set timeout;
29 1         7 $self->set_timeout;
30 1         2 return;
31             }
32              
33 1         44 bless $tx, 'Finance::Bitcoin::Feed::Site::LakeBtc::Socket';
34 1         4 $tx->configure($self);
35 2         3 });
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