邮递员对Binance API的GET请求

时间:2020-04-10 11:13:03

标签: post get request postman binance

我正在尝试向Binance的API发送一个GET请求,但是我不知道该怎么做。 这是文档页面:https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#account-information-user_data

我有一个私人apiKeysecretKey。 我可以向Binance提出一般请求,但无法使用私钥获取我的私有数据。

首先尝试: 对于邮递员中的GET请求,我使用以下字符串: https://api.binance.com/api/v3/account?timestamp=1499827319559&signature= here_I_put_my_secret_key

然后我以header的身份通过,就像Danny推荐的apiKey

但是我得到了

    {
    "code": -1021,
    "msg": "Timestamp for this request is outside of the recvWindow."
    }

谢谢。

3 个答案:

答案 0 :(得分:1)

根据文档,这可能是您想要的。

https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#endpoint-security-type

API密钥通过X-MBX-APIKEY标头传递到Rest API。

在您的请求中,将其添加为标题密钥,并将API密钥添加为值。

答案 1 :(得分:1)

我在Postman中使用javascript解决了此更正时间问题。 另一个简单的解决方法是使用ccxt库:https://github.com/ccxt/ccxt

答案 2 :(得分:0)

从这里获取 Binance API 的官方 Postman 集合:

https://github.com/binance/binance-api-postman

例如在 Postman 中导入所需的集合和环境 binance_spot_api_v1.postman_collection.jsonbinance_com_spot_api.postman_environment.json

将您的 API 密钥添加到 binance-api-key 环境变量,并将您的密钥添加到 binance-api-secret 变量。

注意:限制密钥在币安密钥管理中的作用。不要将此密钥用于生产,仅用于测试。为生产创建新密钥。

对于已签名的请求,在 Pre-request Script 中计算签名,然后设置 signature 环境变量。

示例预请求脚本:

function resolveQueryString() {
  const query = JSON.parse(JSON.stringify(pm.request.url.query)) 
  const keyPairs = []
  for (param of query) {
    if (param.key === 'signature') continue
    if (param.disabled) continue
    if (param.value === null) continue
    const value = param.value.includes('{{') ? pm.environment.get(param.key) : param.value
    keyPairs.push(`${param.key}=${value}`)
  }
  return keyPairs.join('&')
}

const signature = CryptoJS.HmacSHA256(
  resolveQueryString(),
  pm.environment.get('binance-api-secret')
).toString(CryptoJS.enc.Hex)
pm.environment.set('signature', signature)