0

I am trying to hit GDAX using R and getting the following issue. How do I solve for the issue using httr.

Response [https://api-public.sandbox.gdax.com/accounts]
  Date: 2017-12-07 20:30
  Status: 400
  Content-Type: application/json; charset=utf-8
  Size: 53 B

Below is my code. Please note that the issue exists only with httr package and not with RCurl (code provided in appendix)

library(digest)
library(httr)
library(RCurl) # for base64Decode

url <- "https://api-public.sandbox.gdax.com/accounts"
secret <- # API secret from GDAX sandbox
api.key <- # API key from GDAX sandbox
passphrase <- # API passphrase from GDAX sandbox

timestamp <- format(as.numeric(Sys.time()), digits=13) # create nonce
key <- base64Decode(secret, mode="raw") # encode api secret
what <- paste0(timestamp, "GET", req.url)
sign <- base64Encode(hmac(key, what, algo="sha256", raw=TRUE))

connector <- list(url = url, nonce = timestamp, signature = sign))

GET(url=connector$url,
  add_headers(
    'CB-ACCESS-KEY'=api.key,
    'CB-ACCESS-SIGN'=connector$signature,
    'CB-ACCESS-TIMESTAMP'=connector$nonce,
    'CB-ACCESS-PASSPHRASE'=passphrase,
    'Content-Type'='application/json'
  )
)

If however, I use RCurl then I am able to get a response content using the following code.

httpheader <- list('CB-ACCESS-KEY'=api.key,
  'CB-ACCESS-SIGN'=sign,
  'CB-ACCESS-TIMESTAMP'=timestamp,
  'CB-ACCESS-PASSPHRASE'=passphrase,
  'Content-Type'='application/json')

connector <- list(url = url, header = httpheader)

getURLContent(url = connector$url,
  curl=getCurlHandle(useragent="R"),
  httpheader=connector$header)
Drj
  • 1,176
  • 1
  • 11
  • 26
  • 1
    Try using both sets of code to point to a site like https://requestb.in/ so you can see what's actually being sent to the server to see what might be different. – MrFlick Dec 07 '17 at 21:59
  • Where does the `base64Decode` function come from? – MrFlick Dec 07 '17 at 22:02
  • `RCurl` but its a good call out. I was under the impression that it was a `digest` function. I will need to tackle this once the connection is established using `httr`. – Drj Dec 08 '17 at 00:11

2 Answers2

0

Status Code 400 means you are sending a bad request. Something must be missing or in a wrong format. This could be a missing User Agent string.

For every error response you get a message with an exact description why your request was rejected. Read the content of your response.

renklus
  • 776
  • 6
  • 17
0

unless the sandbox was reinstated (I have no info to say it was) it was decommissioned early 2017 with very little in the way of communication and is still down to this date as far as I'm aware. I documented this on the gdax-java lib.

Rob Evans
  • 2,822
  • 1
  • 9
  • 15
  • That makes sense. I was able to get the code to work on `GDAX` however but not on sandbox. – Drj Jan 22 '18 at 19:22