R Binance API HMAC SHA256 签名消息
R Binance API HMAC SHA256 signed message
我尝试使用 binance API 发送已签名的 api 消息,但我一直失败并出现 404 错误。有人可以帮我解决以下代码吗?
library(jsonlite)
library(httr)
library(dplyr)
library(digest)
timestamp <- 1516941586 #as.numeric(as.POSIXct(Sys.time()))
post_message <- paste0(timestamp, 'public.api' ) # data_client.id = client
id # data_key = key
sha.message <- toupper(digest::hmac('private.api', object = post_message,
algo = 'sha256', serialize = F))
url <- 'https://api.binance.com/api/v3/account'
body = list('timestamp' = timestamp, 'signature' = sha.message)
body2 <- paste("?timestamp=",timestamp,"&signature=",sha.message, sep = "")
httr::POST(url, body2 = body, verbose())
这是文档https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md
根据网站 "SIGNED Endpoint Examples for POST /api/v1/order" 部分下的示例,您可以按照类似的方式进行操作。您将需要替换为您自己的 apiKey 和 secretKey。
library(httr)
library(openssl)
url <- 'https://api.binance.com/api/v3/account'
apiKey <- "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A"
secretKey <- "NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j"
timestamp <- 1516941586
recvWindow <- 1e20
postmsg <- paste0("timestamp=", timestamp, "&recvWindow=", recvWindow)
signature <- openssl::sha256(postmsg, key=secretKey)
GET(url,
add_headers("X-MBX-APIKEY"=apiKey),
query=list(timestamp=timestamp, recvWindow=recvWindow, signature=signature),
verbose())
我尝试使用 binance API 发送已签名的 api 消息,但我一直失败并出现 404 错误。有人可以帮我解决以下代码吗?
library(jsonlite)
library(httr)
library(dplyr)
library(digest)
timestamp <- 1516941586 #as.numeric(as.POSIXct(Sys.time()))
post_message <- paste0(timestamp, 'public.api' ) # data_client.id = client
id # data_key = key
sha.message <- toupper(digest::hmac('private.api', object = post_message,
algo = 'sha256', serialize = F))
url <- 'https://api.binance.com/api/v3/account'
body = list('timestamp' = timestamp, 'signature' = sha.message)
body2 <- paste("?timestamp=",timestamp,"&signature=",sha.message, sep = "")
httr::POST(url, body2 = body, verbose())
这是文档https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md
根据网站 "SIGNED Endpoint Examples for POST /api/v1/order" 部分下的示例,您可以按照类似的方式进行操作。您将需要替换为您自己的 apiKey 和 secretKey。
library(httr)
library(openssl)
url <- 'https://api.binance.com/api/v3/account'
apiKey <- "vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A"
secretKey <- "NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j"
timestamp <- 1516941586
recvWindow <- 1e20
postmsg <- paste0("timestamp=", timestamp, "&recvWindow=", recvWindow)
signature <- openssl::sha256(postmsg, key=secretKey)
GET(url,
add_headers("X-MBX-APIKEY"=apiKey),
query=list(timestamp=timestamp, recvWindow=recvWindow, signature=signature),
verbose())