0

DELETE在 R 中遇到请求时遇到问题。我已使用以下代码成功提出GET和请求。POST任何帮助/指针将不胜感激。

它需要来自 GDAX的api.key, secret&才能工作。passphrase

这是我的功能:

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

cancel_order <- function(api.key,
                         secret,
                         passphrase) {
  api.url <- "https://api.gdax.com"

  #get url extension----
  req.url <- "/orders/"

  #define method----
  method = "DELETE"

  url <- paste0(api.url, req.url)

  timestamp <-
    format(as.numeric(Sys.time()), digits = 13) # create nonce
  key <- base64Decode(secret, mode = "raw") # encode api secret

  #create final end point----
  what <- paste0(timestamp, method, req.url)

  #create encoded signature----
  sign <-
    base64Encode(hmac(key, what, algo = "sha256", raw = TRUE)) # hash

  #define headers----
  httpheader <- list(
    'CB-ACCESS-KEY' = api.key,
    'CB-ACCESS-SIGN' = sign,
    'CB-ACCESS-TIMESTAMP' = timestamp,
    'CB-ACCESS-PASSPHRASE' = passphrase,
    'Content-Type' = 'application/json'
  )
  ##------------------------------------------------
  response <- getURL(
    url = url,
    curl = getCurlHandle(useragent = "R"),
    httpheader = httpheader
  )
  print(rawToChar(response)) #rawToChar only on macOS and not on Win
}

我得到的错误是"{\"message\":\"invalid signature\"}"即使相同的命令将编码并且签名将与GET&一起使用POST

参考: GDAX API 文档

4

2 回答 2

0

只是一个猜测,因为我不熟悉 API,但也许你错过了“订单 ID”......

看看:https ://docs.gdax.com/?javascript#cancel-an-order

于 2017-12-28T19:54:19.620 回答
0

行。我接受了@mrflick 的建议,并根据他对一个不同但相关的问题的反馈指出了我与requestbin的联系。

经过仔细检查,我意识到我的请求由于某种原因被视为POST请求而不是DELETE请求。所以我决定getURL用另一个更高级别的函数替换这个函数,RCurl让它工作。

response <- httpDELETE(
  url = url,
  curl = getCurlHandle(useragent = "R"),
  httpheader = httpheader
)

其他一切都保持不变。显然签名从来没有问题。

我现在已将此功能添加到我的非官方包装器rgdax

编辑::
非官方的包装器现在是官方的并且在 CRAN 上。

于 2017-12-29T19:32:46.153 回答