2017-12-10 16 views
1

GDAX APIをRと連携させることが切望されています。 しかし、私は常に「無効な」署名を受け取ります。Rを持つGDAX API:無効な署名

署名が不要なパブリック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からの)署名が構築されるべきかのdiscription

enter image description here

は誰のアイデアを持っているです間違っている? 誰も助けることができますか?ありがとう

以下、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キーを削除し、新しいものを生成した。その後、もう一度試してみましたという意味)と

を、それを試してみました。

+0

問題を解決するR-Wrapper 'rgdax'を作成しました。 https://github.com/DheerajAgarwal/rgdax。 – Drj

答えて

1

メッセージをパスにエンコードするには、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")))