Eugene van der Merwe
Eugene van der Merwe

Reputation: 4670

Convert Bitstamp API Python Example Code to Laravel/PHP SHA256 Algorythm

According to the Bitstamp API docs here https://www.bitstamp.net/api/ the following Python code may be used to generate a SHA256 signature:

import hmac
import hashlib

message = nonce + customer_id + api_key
signature = hmac.new(
    API_SECRET,
    msg=message,
    digestmod=hashlib.sha256
).hexdigest().upper()

I'm trying to use Laravel/PHP with the GuzzleHttp Client to do the same. My code is:

$client  = new \GuzzleHttp\Client();
        $nonce = time();
        $message = $nonce . $bitstamp_customer_id . $bitstamp_api_key;
        $signature = strtoupper(hash_hmac("sha256", $message, $bitstamp_api_secret));
$response = $client->request('POST', 'https://www.bitstamp.net/api/v2/balance/', [
            'form_params' => [
                'key' => $bitstamp_api_key,
                'signature' => $signature,
                'nonce' => $nonce,
            ]
        ]);

No matter what I try I get:

Client error:POST https://www.bitstamp.net/api/v2/balance/resulted in a403 Authentication Failedresponse: {"status": "error", "reason": "API key not found", "code": "API0001"}

I've checked the three critical Bitstamp parameters and recreated the API key multiple times. The three parameters which I have doulble checked are:

I'm concluding I'm not translating the Python code correctly and would like some help.

Upvotes: 1

Views: 290

Answers (1)

Eugene van der Merwe
Eugene van der Merwe

Reputation: 4670

O gosh, I had to press the big green ACTIVATE button and confirm via email.

Upvotes: 1

Related Questions