Acme-Coinbase

 view release on metacpan or  search on metacpan

bin/coinbase.pl  view on Meta::CPAN

    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
        my $sig  = hmac_sha256_hex($nonce . $url . "", $api_secret); 
            # somehow this is different than what we get from non-curl
        print "$prog: in callback, str=$nonce$url, ACCESS_SIGNATURE => $sig\n";
        my $curl = "curl";
        if ($verbose) { $curl .= " --verbose"; }
        my $cmd = "$curl " . 
                    " -H 'Accept: */*' " . 
                    " -H 'Host: coinbase.com' " . 
                    " -H 'ACCESS_KEY: $api_key' " . 
                    " -H 'ACCESS_NONCE: $nonce' " .
                    " -H 'ACCESS_SIGNATURE: $sig' " .

bin/coinbase.pl  view on Meta::CPAN


        # 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;
                my $sig = hmac_sha256_hex( $to_hmac, $api_secret ); 
                print "$prog: in callback, str=$to_hmac, ACCESS_SIGNATURE => $sig\n";
                $request->headers->push_header( ACCESS_SIGNATURE => $sig );
            }
        );

        if ($verbose) {
            # a handler to dump out the request for debugging
            $ua->add_handler( request_send => sub { 
                    #print "$prog: verbose mode: BEGIN dump of request object: ***********\n";
                    #shift->dump; 

bin/coinbase.pl  view on Meta::CPAN


=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.

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

    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
        my $sig  = hmac_sha256_hex($nonce . $url . "", $api_secret); 
            # somehow this is different than what we get from non-curl
        print "$prog: in callback, str=$nonce$url, ACCESS_SIGNATURE => $sig\n";
        my $curl = "curl";
        if ($verbose) { $curl .= " --verbose"; }
        my $cmd = "$curl " . 
                    " -H 'Accept: */*' " . 
                    " -H 'Host: coinbase.com' " . 
                    " -H 'ACCESS_KEY: $api_key' " . 
                    " -H 'ACCESS_NONCE: $nonce' " .
                    " -H 'ACCESS_SIGNATURE: $sig' " .

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


        # 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;
                my $sig = hmac_sha256_hex( $to_hmac, $api_secret ); 
                print "$prog: in callback, str=$to_hmac, ACCESS_SIGNATURE => $sig\n";
                $request->headers->push_header( ACCESS_SIGNATURE => $sig );
            }
        );

        if ($verbose) {
            # a handler to dump out the request for debugging
            $ua->add_handler( request_send => sub { 
                    #print "$prog: verbose mode: BEGIN dump of request object: ***********\n";
                    #shift->dump; 

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


=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.

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

    die "$0: no config file" unless $self->config_file;
    print "$0: Config file is " . $self->config_file . "\n";
    #my $config_hash = Config::INI::Reader->read_file( $self->config_file );
    my $config = Config::IniFiles->new(); # -file => $self->config_file);
    $config->SetFileName( $self->config_file ) || die "$0: Can't set config filename\n";;
    $config->ReadConfig();
    #print "READ: " . $config->OutputConfig();
    $self->config_reader( $config );
}
sub get_param {
    my ($self, $section, $param) = @_;
    return "" unless($self->config_reader) ;
    return $self->config_reader->val( $section, $param ) || "";
}

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

=head1 SYNOPSIS

Example of a usage goes here, such as

    my $conf = new Acme::Coinbase::Config( config_file=>$filename);
    my $conf->read_config();
    my $val = $conf->get_param( "section", "param" );

=head1 DESCRIPTION

Manages reading a config file.

=head1 METHODS

=over 4

=item my $conf = Acme::Coinbase::Config->new( );

returns a new object.  

=item conf->read_config()

reads the config file

=item conf->get_param( "section", "param")

reads the given parameter from the given section. 

=back

=head1 COPYRIGHT

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

=head1 AUTHORS

Josh Rabinowitz

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

    die "$0: no config file" unless $self->config_file;
    print "$0: Config file is " . $self->config_file . "\n";
    #my $config_hash = Config::INI::Reader->read_file( $self->config_file );
    my $config = Config::IniFiles->new(); # -file => $self->config_file);
    $config->SetFileName( $self->config_file ) || die "$0: Can't set config filename\n";;
    $config->ReadConfig();
    #print "READ: " . $config->OutputConfig();
    $self->config_reader( $config );
}
sub get_param {
    my ($self, $section, $param) = @_;
    return "" unless($self->config_reader) ;
    return $self->config_reader->val( $section, $param ) || "";
}

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

=head1 SYNOPSIS

Example of a usage goes here, such as

    my $conf = new Acme::Coinbase::Config( config_file=>$filename);
    my $conf->read_config();
    my $val = $conf->get_param( "section", "param" );

=head1 DESCRIPTION

Manages reading a config file.

=head1 METHODS

=over 4

=item my $conf = Acme::Coinbase::Config->new( );

returns a new object.  

=item conf->read_config()

reads the config file

=item conf->get_param( "section", "param")

reads the given parameter from the given section. 

=back

=head1 COPYRIGHT

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

=head1 AUTHORS

Josh Rabinowitz

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.

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.



( run in 1.065 second using v1.01-cache-2.11-cpan-39bf76dae61 )