问题
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)
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/47704167/r-httr-get-request-400-error-gdax