GDAX API 与 R:无效签名

GDAX API with R: invalid signature

我拼命想让 GDAX API 与 R 一起工作。 但是我总是收到消息 "invalid" signature.

当我使用 public API 时,无需签名,我可以毫无问题地使用 APi。

这是我的代码

library(httr)
library(jsonlite)
library(digest)
library(RCurl)

api.key <- "My API Key"
secret <- "MY API secret"
passphrase <- "my passphrase"

url <- "https://api.gdax.com"

timestamp <- format(as.numeric(Sys.time()), digits=13)
method <- "GET"
requestPath <- paste0(url,"/accounts")

dec.key <- base64Decode(secret , mode = "raw")

message <- paste0(timestamp,toupper(method),requestPath)

signature <- base64Encode( hmac(key = dec.key, object = message, algo = 
"sha256" , raw=T))

content( GET(requestPath,
         add_headers(
           "CB-ACCESS-KEY" = api.key, 
           "CB-ACCESS-SIGN" = signature,
           "CB-ACCESS-TIMESTAMP" = timestamp,
           "CB-ACCESS-PASSPHRASE" = passphrase,
           "Content-Type"="application/json")) )

这是关于如何构建签名的说明(来自 GDAX)

有人知道我做错了什么吗? 谁能帮忙?谢谢

下面,我还 post vebose() 输出。因为这可能会有所帮助。

-> GET /accounts HTTP/1.1
-> Host: api.gdax.com
-> User-Agent: libcurl/7.56.0 r-curl/3.0 httr/1.3.1
-> Accept-Encoding: gzip, deflate
-> Cookie: __cfduid=d924b4a32e77ec4527316deee73e313da1512985465
-> Accept: application/json, text/xml, application/xml, */*
-> CB-ACCESS-KEY: "My API Key"
-> CB-ACCESS-SIGN: "generated signature"
-> CB-ACCESS-TIMESTAMP: 1512985492.905
-> CB-ACCESS-PASSPHRASE: "my passphrase"
-> Content-Type: application/json
-> 
<- HTTP/1.1 400 Bad Request
<- Date: Mon, 11 Dec 2017 09:44:54 GMT
<- Content-Type: application/json; charset=utf-8
<- Content-Length: 31
<- Connection: keep-alive
<- Access-Control-Allow-Headers: Content-Type, Accept, cb-session, cb-fp
<- Access-Control-Allow-Methods: GET,POST,DELETE,PUT
<- Access-Control-Allow-Origin: *
<- Access-Control-Expose-Headers: cb-before, cb-after
<- Access-Control-Max-Age: 7200
<- ETag: W/"1f-4RjKVp8I05+xcnQ5/G16yRoMSKU"
<- Strict-Transport-Security: max-age=15552000; includeSubDomains; preload
<- X-Content-Type-Options: nosniff
<- Server: cloudflare-nginx
<- CF-RAY: 3cb782099f053eb0-ZRH
<- 
<<  {"message":"invalid signature"}

*  Connection #12 to host api.gdax.com left intact

我还尝试了不同的 API 密钥/签名/密码(意思是我删除了 API 密钥并生成了一个新密钥。然后再次尝试)

非常感谢任何帮助。

您必须使用 as requestPath 将消息编码为 GDAX API 描述中的路径。 在这种情况下:

requestPath <- "/accounts"
fullPath <- paste0(url, requestPath)

请记住使用完整路径作为 API 的 URL 端点。

content(GET(fullPath,
     add_headers(
       "CB-ACCESS-KEY" = api.key, 
       "CB-ACCESS-SIGN" = signature,
       "CB-ACCESS-TIMESTAMP" = timestamp,
       "CB-ACCESS-PASSPHRASE" = passphrase,
       "Content-Type"="application/json")))