How to: New order Binance API via RStudio

强颜欢笑 提交于 2020-01-05 04:25:07

问题


I am trying to create a new order via the Binance API using RStudio.

I found the Binance Official API Docs and figured out that I should use

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

The following script doesn't work out for me:

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())

Does anyone know what I'm doing wrong and how I can create an order via the Binance API using RSTUDIO and how I can create my signature?


回答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()
)


来源:https://stackoverflow.com/questions/50338392/how-to-new-order-binance-api-via-rstudio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!