Acme-Coinbase

 view release on metacpan or  search on metacpan

bin/coinbase.pl  view on Meta::CPAN

        "nonce=n" => \$nonce,
    ) or die Usage();
    $SIG{__WARN__} = sub { Carp::confess $_[0] };
    $SIG{__DIE__} = sub { Carp::confess $_[0] };

    print "$prog: NONCE: $nonce\n";
    my $base = "https://api.coinbase.com/api"; 
    #my $base = "https://api.coinbase.com";
    my $url  = "$base/v1/account/balance";

    my $default_config_file = $ENV{HOME} . "/.acmecoinbase.ini";
    if (!$config_file && -e $default_config_file) {
        $config_file = $default_config_file;
    }
    my $config = Acme::Coinbase::Config->new( );
    if ($config_file && -e $config_file) {
        $config->config_file($config_file);
        $config->read_config();
    }
    my $api_key    = $config->get_param("default", "api_key")    || $auth->api_key(); 
    my $api_secret = $config->get_param("default", "api_secret") || $auth->api_secret();
    #print "$prog: using API key $api_key\n";

    perform_request( $url, $api_key, $api_secret, $verbose );
}


sub perform_request {
    my ( $url, $api_key, $api_secret, $verbose ) = @_;
    if ($use_curl) {
        # use curl to do basic request

bin/coinbase.pl  view on Meta::CPAN

                    " -H 'ACCESS_SIGNATURE: $sig' " .
                    " -H 'Connection: close' " . 
                    " -H 'Content-Type: application/json' " . 
                    " $url";
        print "$cmd\n";
        system( $cmd );
        print "\n";
    } else {
        # use LWP::UserAgent
        my $ua = LWP::UserAgent->new();
        $ua->default_headers->push_header( Accept       => "*/*" );
        $ua->default_headers->push_header( ACCESS_KEY   => $api_key );
        $ua->default_headers->push_header( ACCESS_NONCE => $nonce );
        $ua->default_headers->push_header( Host         => "coinbase.com" );
        $ua->default_headers->push_header( Connection   => "close" );
        $ua->default_headers->push_header( "Content-Type" => "application/json" );

        # add ACCESS_SIGNATURE in a request_prepare handler so we can set it knowing the request content
        # ... it doesn't matter for GETs though because the content should be blank (like we see in our code)
        $ua->add_handler( 
            request_prepare => sub { 
                my($request, $ua, $h) = @_; 
                my $content = $request->decoded_content();  # empty string.
                $content = "" unless defined($content);

                my $to_hmac = $nonce . $url . $content;

bin/coinbase.pl  view on Meta::CPAN


Overall view of the options

    coinbase.pl [-verbose] [--use-curl] [--nonce=NONCE] [--config=CONF.ini]

=over 4

=item --config=/dif/coinbase.ini

Set path to an acmecoinbase.ini file. 
The will default to ~/.acmecoinbase.ini

This file is expected to have contents like:

    [default]
    api_key    = 123456apikeyfgYZ
    api_secret = ZZZ111apisecret333DDD444EEE555ZZ

For now, the [default] part is mandatory.

=item --verbose/--noverbose

Turns on/off verbose mode. (off by default)

=item --use-curl

Use curl instead of perl LWP libraries, for test purposes.

=item --nonce=NUMBER

Hard code the nonce to a particular number. For testing. 
(Techically this is supposed to 'always increase')

bin/coinbase.pl.bak  view on Meta::CPAN

        "nonce=n" => \$nonce,
    ) or die Usage();
    $SIG{__WARN__} = sub { Carp::confess $_[0] };
    $SIG{__DIE__} = sub { Carp::confess $_[0] };

    print "$prog: NONCE: $nonce\n";
    my $base = "https://api.coinbase.com/api"; 
    #my $base = "https://api.coinbase.com";
    my $url  = "$base/v1/account/balance";

    my $default_config_file = $ENV{HOME} . "/.acmecoinbase.ini";
    if (!$config_file && -e $default_config_file) {
        $config_file = $default_config_file;
    }
    my $config = Acme::Coinbase::Config->new( );
    if ($config_file && -e $config_file) {
        $config->config_file($config_file);
        $config->read_config();
    }
    my $api_key    = $config->get_param("default", "api_key")    || $auth->api_key(); 
    my $api_secret = $config->get_param("default", "api_secret") || $auth->api_secret();
    #print "$prog: using API key $api_key\n";

    perform_request( $url, $api_key, $api_secret, $verbose );
}


sub perform_request {
    my ( $url, $api_key, $api_secret, $verbose ) = @_;
    if ($use_curl) {
        # use curl to do basic request

bin/coinbase.pl.bak  view on Meta::CPAN

                    " -H 'ACCESS_SIGNATURE: $sig' " .
                    " -H 'Connection: close' " . 
                    " -H 'Content-Type: application/json' " . 
                    " $url";
        print "$cmd\n";
        system( $cmd );
        print "\n";
    } else {
        # use LWP::UserAgent
        my $ua = LWP::UserAgent->new();
        $ua->default_headers->push_header( Accept       => "*/*" );
        $ua->default_headers->push_header( ACCESS_KEY   => $api_key );
        $ua->default_headers->push_header( ACCESS_NONCE => $nonce );
        $ua->default_headers->push_header( Host         => "coinbase.com" );
        $ua->default_headers->push_header( Connection   => "close" );
        $ua->default_headers->push_header( "Content-Type" => "application/json" );

        # add ACCESS_SIGNATURE in a request_prepare handler so we can set it knowing the request content
        # ... it doesn't matter for GETs though because the content should be blank (like we see in our code)
        $ua->add_handler( 
            request_prepare => sub { 
                my($request, $ua, $h) = @_; 
                my $content = $request->decoded_content();  # empty string.
                $content = "" unless defined($content);

                my $to_hmac = $nonce . $url . $content;

bin/coinbase.pl.bak  view on Meta::CPAN


Overall view of the options

    coinbase.pl [-verbose] [--use-curl] [--nonce=NONCE] [--config=CONF.ini]

=over 4

=item --config=/dif/coinbase.ini

Set path to an acmecoinbase.ini file. 
The will default to ~/.acmecoinbase.ini

This file is expected to have contents like:

    [default]
    api_key    = 123456apikeyfgYZ
    api_secret = ZZZ111apisecret333DDD444EEE555ZZ

For now, the [default] part is mandatory.

=item --verbose/--noverbose

Turns on/off verbose mode. (off by default)

=item --use-curl

Use curl instead of perl LWP libraries, for test purposes.

=item --nonce=NUMBER

Hard code the nonce to a particular number. For testing. 
(Techically this is supposed to 'always increase')

lib/Acme/Coinbase/Config.pm  view on Meta::CPAN

}

sub dump {
    my $self = shift;

    my @sections = $self->config_reader->Sections();
    return "Sections: " . Dumper( \@sections ) . "\n";
}

# dummy data
#has 'api_key'    => (is => 'rw', isa => 'Str', default=>"lmnop");
#has 'api_secret'  => (is => 'rw', isa => 'Str', default=>"qwerty");

#############################################
# we expect a config file, if used, to look like:
#  [default]
#  api_key    = keyasdakjb34234kj
#  api_secret = secretk3j4204h554j2h3409u34bn
#############################################

1;

=head1 NAME

Acme::Coinbase::Config --  DEPRECATED. Use Finance::GDAX::API or WebService::Coinbase

lib/Acme/Coinbase/Config.pm.bak  view on Meta::CPAN

}

sub dump {
    my $self = shift;

    my @sections = $self->config_reader->Sections();
    return "Sections: " . Dumper( \@sections ) . "\n";
}

# dummy data
#has 'api_key'    => (is => 'rw', isa => 'Str', default=>"lmnop");
#has 'api_secret'  => (is => 'rw', isa => 'Str', default=>"qwerty");

#############################################
# we expect a config file, if used, to look like:
#  [default]
#  api_key    = keyasdakjb34234kj
#  api_secret = secretk3j4204h554j2h3409u34bn
#############################################

1;

=head1 NAME

Acme::Coinbase::Config -- read a acmecoinbase config file

lib/Acme/Coinbase/DefaultAuth.pm  view on Meta::CPAN

package Acme::Coinbase::DefaultAuth;
# vim: set ts=4 sw=4 expandtab showmatch
#
use strict;

# FOR MOOSE
use Moose; # automatically turns on strict and warnings

# these are for our TEST account 
has 'api_key'    => (is => 'rw', isa => 'Str', default=>"pl5Yr4RK487wYpB2");
has 'api_secret' => (is => 'rw', isa => 'Str', default=>"TusAkTDkRqtDJrSXzn06aUCa6e8gt8Bh");

1;
=head1 NAME

Acme::Coinbase::DefaultAuth -- DEPRECATED. Use Finance::GDAX::API or WebService::Coinbase

=head1 SYNOPSIS

Example of a usage goes here, such as...
    
    my $key    = Acme::Coinbase::DefaultAuth::api_key();
    my $secret = Acme::Coinbase::DefaultAuth::api_secret();

=head1 DESCRIPTION

Holds default, test api creds

=head1 METHODS

=head1 COPYRIGHT

Copyright (c) 2018 Josh Rabinowitz, All Rights Reserved.

=head1 AUTHORS

Josh Rabinowitz

lib/Acme/Coinbase/DefaultAuth.pm.bak  view on Meta::CPAN

package Acme::Coinbase::DefaultAuth;
# vim: set ts=4 sw=4 expandtab showmatch
#
use strict;

# FOR MOOSE
use Moose; # automatically turns on strict and warnings

# these are for our TEST account 
has 'api_key'    => (is => 'rw', isa => 'Str', default=>"pl5Yr4RK487wYpB2");
has 'api_secret' => (is => 'rw', isa => 'Str', default=>"TusAkTDkRqtDJrSXzn06aUCa6e8gt8Bh");

1;
=head1 NAME

Acme::Coinbase::DefaultAuth -- Default test creds for coinbase

=head1 SYNOPSIS

Example of a usage goes here, such as...
    
    my $key    = Acme::Coinbase::DefaultAuth::api_key();
    my $secret = Acme::Coinbase::DefaultAuth::api_secret();

=head1 DESCRIPTION

Holds default, test api creds

=head1 METHODS

=head1 COPYRIGHT

Copyright (c) 2014 Josh Rabinowitz, All Rights Reserved.

=head1 AUTHORS

Josh Rabinowitz



( run in 0.448 second using v1.01-cache-2.11-cpan-8780591d54d )