Chart-Plotly

 view release on metacpan or  search on metacpan

examples/bitcoin.pl  view on Meta::CPAN


sub get_bitcoin_data {
    use LWP::UserAgent;
    use HTTP::CookieJar::LWP;
    my $ua = LWP::UserAgent->new( cookie_jar => HTTP::CookieJar::LWP->new );
    $ua->agent('Mozilla/5.0');    # LWP UserAgent banned by default... Don't shoot the messenger...
    $ua->default_header( 'Content-Type' => 'application/json' );
    my $response = $ua->get('https://api.pro.coinbase.com/products/BTC-EUR/candles');

    if ( $response->is_success() ) {
        my $data = from_json( $response->decoded_content );
        my ( @x, @open, @close, @high, @low );
        for my $candle (@$data) {
            push @x, DateTime->from_epoch( epoch => $candle->[0] );
            push @low,   $candle->[1];
            push @high,  $candle->[2];
            push @open,  $candle->[3];
            push @close, $candle->[4];
        }
        return { x     => \@x,
                 open  => \@open,



( run in 0.235 second using v1.01-cache-2.11-cpan-26ccb49234f )