Finance::Bitcoin::Feed - Collect bitcoin real-time price from many sites' streaming data source
use Finance::Bitcoin::Feed; #default output is to print to the stdout Finance::Bitcoin::Feed->new->run(); # will print output to the stdout: # COINSETTER BTCUSD 123.00 #or custom your stdout open my $fh, ">out.txt"; $fh->autoflush(); my $feed = Finance::Bitcoin::Feed->new(output => sub{ my ($self, $site, $currency, $price) = @_; print $fh "the price currency $currency on site $site is $price\n"; }); # let's go! $feed->run(); #you can also custom which site you want to connect Finance::Bitcoin::Feed->new(sites => [qw(LakeBtc)])->go;
Finance::Bitcoin::Feed is a bitcoin realtime data source which collect real time data source from these sites:
HitBtc
BtcChina
CoinSetter
<lakebtc api
The default output format to the stdout by this format:
site_name TIMESTAMP CURRENCY price
For example:
COINSETTER 1418173081724 BTCUSD 123.00
The unit of timestamp is ms.
You can custom your output by listen on the event output and modify the data it received.
Note the followiing sites doesn't give the timestamp. So the timestamp in the result will be 0:
LakeBtc
This class inherits all methods from Mojo::EventEmitter
This method have two arguments by which you can costumize the behavior of the feed:
which sites you want to connect. It is in fact the array reference of module names of Finance::Bitcoin::Feed::Site::*. Now it have 4 modules: Hitbtc BtcChina CoinSetter LakeBtc
You can also put your own site module under this namespace and added here.
customize the output format by giving this argument a sub reference. It will be bind to the event 'output'. Please rever to the event <output>.
# you can customize the output by giving argument 'output' to the new methold open my $fh, ">out.txt"; $fh->autoflush(); my $feed = Finance::Bitcoin::Feed->new(output => sub{ my ($self, $site, $timestamp, $currency, $price) = @_; print $fh "the price currency $currency on site $site is $price\n"; }); # let's go! $feed->run();
This class inherits all events from Mojo::EventEmitter and add the following new ones:
This event has a default subscriber:
#output to the stdout, the default action: $feed->on('output', sub { shift; say join " ", @_ } );
You can customize the output by giving argument 'output' to the new method
open my $fh, ">out.txt"; $fh->autoflush(); my $feed = Finance::Bitcoin::Feed->new(output => sub{ my ($self, $site, $timestamp, $currency, $price) = @_; print $fh "the price currency $currency on site $site is $price\n"; }); # let's go! $feed->run();
Or you can bind output directly to the feed to get multi outout or you should unscribe this event first.
$feed->on('output', sub {....})
The arguments of this event is:
$self: the site class object timestamp: the timestamp of the data. If no timestamp is given by the site, then the value of it is 0. sitename: the site class name price: the price
You can set the FINANCE_BITCOIN_FEED_DEBUG environment variable to get some advanced diagnostics information printed to STDERR. And these modules use Mojo::UserAgent, you can also open the MOJO_USERAGENT_DEBUG environment variable:
FINANCE_BITCOIN_FEED_DEBUG=1 MOJO_USERAGENT_DEBUG=1
Mojo::EventEmitter
Finance::Bitcoin::Feed::Site::Hitbtc
Finance::Bitcoin::Feed::Site::BtcChina
Finance::Bitcoin::Feed::Site::CoinSetter
Finance::Bitcoin::Feed::Site::LakeBtc
Chylli <chylli@binary.com>
<chylli@binary.com>
Copyright 2014- Binary.com
To install Finance::Bitcoin::Feed, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Finance::Bitcoin::Feed
CPAN shell
perl -MCPAN -e shell install Finance::Bitcoin::Feed
For more information on module installation, please visit the detailed CPAN module installation guide.