我正尝试使用 R 命中 GDAX ,并获得以下问题。如何使用 httr 解决问题。
响应[https ://api-public.sandbox.gdax/accounts] 日期:2017-12-07 20:30 状态:400 Content-Type:application / json; charset = utf-8 大小:53 B以下是我的代码。请注意,这个问题只存在于 httr 包而不是 RCurl (代码见附录)
$ b $ library(digest) library(httr) library(RCurl)#for base64Decode url< - api-public.sandbox.gdax/accounts秘密&#;#来自GDAX沙箱的API秘密 api.key< - #API密钥来自GDAX沙箱密码短语< - #来自GDAX沙箱的API密码短语 时间戳< - 格式(as.numeric(Sys.time()),digits = 13)#创建nonce key< - base64Decode(secret,mode =raw)#encode api secret what < - paste0(timestamp,GET,req.url) sign< - base64Encode( hmac(key,what,algo =sha256,raw = TRUE)) 连接器< - list(url = url,nonce = timestamp,signature = sign)) GET(url = connector $ url, add_headers('CB-ACCESS-KEY'= api.key,'CB-ACCESS-SIGN'=连接器$签名,'CB-ACCESS-TIMESTAMP'=连接器$ nonce, 'CB-ACCESS-PASSPHRASE'=密码,'Content-Type'='application / json'))但是,如果我使用 RCurl ,那么我可以使用以下代码获得响应内容。
解决方案除非沙箱被恢复(我没有资料可以这样说),但是它在2017年年初退役,通讯方式很少,而且据我所知,仍然是这个日期。我将它记录在 gdax-java 库中。
I am trying to hit GDAX using R and getting the following issue. How do I solve for the issue using httr.
Response [api-public.sandbox.gdax/accounts] Date: 2017-12-07 20:30 Status: 400 Content-Type: application/json; charset=utf-8 Size: 53 BBelow 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 <- "api-public.sandbox.gdax/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)解决方案
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.
更多推荐
R httr GET请求400错误GDAX
发布评论