Acme-Coinbase
view release on metacpan or search on metacpan
bin/coinbase.pl view on Meta::CPAN
#!/usr/bin/perl -w
# vim: set ts=4 sw=4 expandtab showmatch
# PODNAME: coinbase.pl
# above is for POD::Weaver
use strict;
use Getopt::Long;
use Acme::Coinbase::DefaultAuth;
use Acme::Coinbase::Config;
use File::Basename;
use Digest::SHA qw(hmac_sha256_hex);
use LWP::UserAgent;
use Data::Dumper;
use Carp;
use Time::HiRes;
use bignum;
my $prog = basename($0);
my $verbose;
my $auth = Acme::Coinbase::DefaultAuth->new();
#my $nonce = time();
my $nonce = Time::HiRes::time() * 1E6;
my $config_file;# = $ENV{HOME} . "/.acmecoinbase.ini";
my $use_curl = 0;
# Usage() : returns usage information
sub Usage {
"$prog [--verbose] [--use-curl] [--nonce=NONCE] [--config=CONF.ini]\n";
}
# call main()
main();
# main()
sub main {
GetOptions(
"verbose!" => \$verbose,
"config-file=s" => \$config_file,
"use-curl" => \$use_curl,
"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
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";
( run in 2.489 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )