Calling BitStamp API using Guzzle
I’ve recently been working on integrating to the BitStamp API from a Laravel application, and I was having some problems calling it using the Guzzle PHP HTTP Client.
I’m sharing how I was finally able to make a call to the API.
The API supports 2 types of calls:
- public calls, e.g to get the market ticker
- private calls, e.g. to get your account balance. The private calls require you to pass some extra details required for authentication, i.e.
key
,nonce
&signature
.
The signature is generated using an algorithm they’ve defined in their docs. I’ve written a post to demonstrate how to do this in PHP here.
I have a function that will handle calling different endpoints on the API, so I just have to send pass the following:
endpoint
requestType
queryParams
forGET
if required,- a flag,
requiresAuth
to determine if we need to pass additional authentication params, and; - the
requestBody
, which contains anyPOST
parameters required.
For calls that require authentication, the key
, nonce
& signature
should be passed as form_params.
One thing to note, if you pass the endpoint
parameter without a trailing slash, e.g. ticker
instead of ticker/
, you’ll get an error saying:
An example of a call to this function would be:
That’s all for now people! Back to code!