R中的401未经授权的错误Binance API

时间:2018-08-03 22:10:00

标签: r api sha256 hmac binance

我正在尝试使用RStudio通过Binance API创建新订单。

我找到了Binance官方API文档,并发现我应该使用:

POST /api/v3/order (HMAC SHA256).

以下脚本无法正常工作,并提供了状态代码:HTTP / 1.1 401未经授权

key <- "*[my key]*"
secret <- "*[my secret key]*"
url='https://api.binance.com/api/v3/order'
timestamp <- as.character(jsonlite::fromJSON(content(GET('https://api.binance.com/api/v1/time'), "text"))$serverTime + 999)
query <- list( "symbol" = "XLMBTC", "side" = "BUY", "type" = "MARKET", "quantity" = 10, "recvWindow" = 5000, "timestamp" = timestamp )
signature <- digest::hmac(key = secret, object = paste(names(query), query, sep = "=", collapse = "&"), algo = "sha256")
POST(url, add_headers("X-MBX-APIKEY"= key), query = c(query, signature = signature), verbose())

我的编码中是否有错误?我以前尝试过一次,然后效果很好。但是,现在我无法提出一个有效的脚本。

在这里您可以找到有关Binance API的文档: https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md

有人可以帮我吗?

1 个答案:

答案 0 :(得分:1)

已经解决了。 Ik检查了该网站的解决方案: https://gunbot.shop/error-response-code-400-on-binance-how-to-fix/

问题是我的API和SECRET密钥已损坏。