Getting total account balance and account balance history

Hi, is there any way i can get a user’s total account balance and balance history? similar to the graph you see under assets page

Hi @jcml

Welcome to the Coinbase Cloud Forum! You can utilise the Accounts endpoint for retrieving balances & Transactions endpoint to retrieve the transaction history of the user under Sign in with Coinbase.

We hope this is helpful. Please let us know if you have further questions.

I’d like some help with this as well.

I just want a simple total account balance to 2 decimal places - exactly as shown on the web page.

I feel I am close, but just need that final point in the right direction.

I use Linux and am very familiar with BASH scripting and CURL.

This is the error I am getting:-

www-authenticate: Bearer realm=“Doorkeeper”, error=“invalid_token”, error_description=“The access token is invalid”

I have chosen PHP for my first attempt.

<?php

require __DIR__ . '/vendor/autoload.php';

use Curl\Curl;

const API_KEY = 'xxxxxxxxxxxxxxx';
const API_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';

$url1 = 'https://api.coinbase.com/v2/time';
$curl1 = new Curl();
$curl1->get($url1);
$timestamp = $curl1->response->data->epoch;
$request_method = 'GET';
$request_path = '/v2/accounts';
$message = $timestamp . $request_method . $request_path;
$signature = hash_hmac('sha256', $message, API_SECRET);
echo 'CB-ACCESS_KEY: ' . API_KEY . "\n";
echo 'CB-ACCESS_SIGN: ' . $signature . "\n";
echo 'CB-ACCESS-TIMESTAMP: ' . $timestamp . "\n";

// curl https://api.coinbase.com/v2/accounts -H 'Authorization: Bearer abd90df5f27a7b170cd775abf89d632b350b7c1c9d53e08b340cd9832ce52c2c'
echo "curl -v https://api.coinbase.com/v2/accounts -H 'Authorization: Bearer $signature'\n";
$exec = "curl -v https://api.coinbase.com/v2/accounts -H 'Authorization: Bearer $signature'\n";

exec ($exec);


What am I doing wrong?

Regards,

Paully

Why are you mixing OAuth2 with API key authentication?

Just pass access key, signature and timestamp headers to curl:

curl https://api.coinbase.com/v2/user \
  --header "CB-ACCESS-KEY: <your api key>" \
  --header "CB-ACCESS-SIGN: <the user generated message signature>" \
  --header "CB-ACCESS-TIMESTAMP: <a timestamp for your request>"
1 Like

Ah yes, my bad. I got so impatient I was trying everything :slight_smile:

So, it now authenticates with API Key and curl.

How do I get a balance ? Do I need to add up all the assets?