2
votes

I'm trying to send a GET request to Binance's API, but I don't exactly know how to. Here is the documentation page: https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#account-information-user_data

I have a private apiKey and secretKey. I can do a general request to Binance, but I cannot get my private data, using my private keys.

First try: For the GET request in Postman I use this string: https://api.binance.com/api/v3/account?timestamp=1499827319559&signature=here_I_put_my_secret_key

And I pass as a header as Danny suggested the apiKey.

But I get:

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

Thanks.

3
Well, there's about 28 mentions of recvWindow in the docs so that's a good place to start. "It is recommended to use a small recvWindow of 5000 or less! The max cannot go beyond 60,000!" - Danny Dainton
I think just reading the documentation will help you here - github.com/binance-exchange/binance-official-api-docs/blob/… - Danny Dainton
Thanks for your response, I already try to set recvWindow=3000 or 50000 but it still generates the error.. - l000000l
I also tried to change timestamp value but nothing is changing.. - l000000l

3 Answers

3
votes

I solved this correcting the time using javascript in Postman. Another easy fix is to use the ccxt library : https://github.com/ccxt/ccxt

1
votes

This might be what you're after, as per the documentation.

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

API-keys are passed into the Rest API via the X-MBX-APIKEY header.

In your Request, add that as the header key and your API Key as the value.

0
votes

Get the official Postman collections for the Binance API from here:

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

Import the desired collection and environment in Postman, for instance binance_spot_api_v1.postman_collection.json and binance_com_spot_api.postman_environment.json

Add your API key to the binance-api-key environment variable and your secret key to the binance-api-secret variable.

CAUTION: Limit what the key can do in Binance key management. Do not use this key for production, only for testing. Create new key for production.

For the signed requests calculate the signature in a Pre-request Script then set the signature environment variable.

Example Pre-request Script:

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)