ownlifeful has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks, Happy 4th of July!
Coinbase has a REST-ful API and offers code snippets in NodeJS, Python, Ruby, and PHP to connect to this API. I think a snippet showing how to connect to the latest Coinbase API in Perl would be useful to many. So I created an account on pro.coinbase.com and got an API key. I wrote the following code, based on the examples in other languages. It looks correct, but does not authenticate. I would appreciate any help. You don't have to create an account, as I've included my API key and secret key.
Please help me get this code talking to Coinbase. The API Documentation is here.
use Modern::Perl; use LWP::UserAgent; use JSON; use Digest::SHA qw(hmac_sha256_base64 hmac_sha256_hex hmac_sha256); use MIME::Base64; my $uri = 'https://api-public.sandbox.pro.coinbase.com'; my $api_key = '6dc071df2d42724c019f79a53464d006'; my $secret = 'vjYZFn39LEFfbJ5z9QzdWt+HsahYTPvXInoYMD9Gq754FJL0evlG +nHcTiaaITGF+6GfbyYnxoyCXji9OR1iEMw=='; my $passphrase = "There is no passphrase.", my $timestamp = time(); my $request_method = "GET"; my $request_path = '/products'; my $body = ''; my $message = $timestamp . $request_method . $request_path . $b +ody; my $decoded_secret = decode_base64($secret); my $signature_b64 = encode_base64( hmac_sha256($message, $decoded_secr +et) ); chomp($signature_b64); my $ua = LWP::UserAgent->new; my $res = $ua->get( $uri, 'CB-ACCESS-SIGN' => $signature_b64, 'CB-ACCESS-TIMESTAMP' => $timestamp, 'CB-ACCESS-KEY' => $api_key, 'CB-ACCESS-PASSPHRASE' => $passphrase, 'Content-Type' => 'application/json' ); if ($res->is_success) { say $res->decoded_content; } else { say "request failed."; say "status:", $res->status_line; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Coinbase API
by hippo (Archbishop) on Jul 04, 2018 at 22:11 UTC | |
by Your Mother (Archbishop) on Jul 05, 2018 at 08:41 UTC | |
by hippo (Archbishop) on Jul 05, 2018 at 09:01 UTC | |
by Your Mother (Archbishop) on Jul 05, 2018 at 09:24 UTC | |
by ownlifeful (Beadle) on Jul 05, 2018 at 12:29 UTC | |
by ownlifeful (Beadle) on Jul 04, 2018 at 22:28 UTC | |
|
Re: Coinbase API
by Your Mother (Archbishop) on Jul 05, 2018 at 10:55 UTC | |
by marto (Cardinal) on Jul 05, 2018 at 10:59 UTC | |
|
Re: Coinbase API
by Your Mother (Archbishop) on Jul 04, 2018 at 21:14 UTC | |
by ownlifeful (Beadle) on Jul 04, 2018 at 21:41 UTC |