1

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

我找到了 Binance Official API Docs 并发现我应该使用

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

以下脚本对我不起作用:

url='https://api.binance.com/api/v3/account'

GET(url, 
    add_headers("X-MBX-APIKEY"= *[my API key]*),
    query=list("symbol"="ETHBTC", 
               "side"="BUY", 
               "type"="MARKET", 
               "quantity"=1, 
               recvWindow=5000, 
               "timestamp"=1499827319559, 
               "signature"=**???**), 
    verbose())

有谁知道我做错了什么以及如何使用 RSTUDIO 通过 Binance API 创建订单以及如何创建我的签名?

4

1 回答 1

1
library(httr)

timestamp <-
  as.character(jsonlite::fromJSON(content(
    GET("https://api.binance.com/api/v1/time"), "text"
  ))$serverTime + 999)

query <-
  list(
    "symbol" = "VENBTC",
    "side" = "BUY",
    "type" = "MARKET",
    "quantity" = 1,
    "recvWindow" = 5000,
    "timestamp" = timestamp
  )

signature <-
  digest::hmac(
    key = "*[my secret key]*",
    object = paste(names(query), query, sep = "=", collapse = "&"),
    algo = "sha256"
  )

POST(
  url,
  add_headers("X-MBX-APIKEY" = "*[my API key]*"),
  query = c(query, signature = signature),
  verbose()
)
于 2018-05-18T15:49:20.937 回答