Binance API Keys

I set the read-only API key on Binance to access account data such as foreign currency balances, but I cannot see the JSON data. The string request entered in the URL returns the following error:

{"code": - 2014, "msg": "Invalid API key format." }

The URL I use is: https://api.binance.com/api/v3/account?X-MBX-APIKEY=**key**&signature=**s-key**

The documentation for the Binance API can be found here: https://www.binance.com/restapipub.html . What am I doing wrong?

+5
source share
6 answers

You should set the API key in the request header, and not as a parameter in the request URL. Please provide additional information about the request procedure (language, etc.).

0

X-MBX-APIKEY HTTP, HTTP. . HTTP. , Excel .

- .

0

:

base_url="https://api.binance.com"
account_info="/api/v3/account"

url="${base_url}${account_info}"

apikey="your_apikey"
secret="your_secret"

queryString="timestamp=$(date +%s)" #$(python3 binance_time.py) must sync
requestBody=""

signature="$(echo -n "${queryString}${requestBody}" | openssl dgst -sha256 -hmac $secret)"
signature="$(echo $signature | cut -f2 -d" ")"

req=$(curl -H "X-MBX-APIKEY: $apikey" -X GET "$url?$queryString&signature=$signature")
echo $req
0

API Binance websocket . .

  1. HTTP- POST API X-MBX-APIKEY https://api.binance.com/api/v1/userDataStream.
  2. , -. 1 .

    {"listenKey": " "}

  3. Binance websocket

wss://stream.binance.com:9443/ws/{your listen key here}

Python

import ssl
from websocket import create_connection

import requests

KEY = 'your-secret-key'
url = 'https://api.binance.com/api/v1/userDataStream'
listen_key = requests.post(url, headers={'X-MBX-APIKEY': KEY})['listenKey']
connection = create_connection('wss://stream.binance.com:9443/ws/{}'.format(KEY), 
                               sslopt={'cert_reqs': ssl.CERT_NONE})
0

You put it in a hat. The following is a proven PHP example borrowed from the jaggedsoft binance PHP library, this is a signed request that will return the status of the account.

$api_key = "cool_key";
$secret = "awesome_secret";

$opt = [
    "http" => [
        "method" => "GET",
        "header" => "User-Agent: Mozilla/4.0 (compatible; PHP Binance API)\r\nX-MBX-APIKEY: {$api_key}\r\n"
    ]
];
$context = stream_context_create($opt);
$params['timestamp'] = number_format(microtime(true)*1000,0,'.','');
$query = http_build_query($params, '', '&');
$signature = hash_hmac('sha256', $query, $secret);
$endpoint = "https://api.binance.com/wapi/v3/accountStatus.html?{$query}&signature={$signature}";

$res = json_decode(file_get_contents($endpoint, false, $context), true);
0
source

curl -H "X-MBX-APIKEY: your_api_key" -X POST https://api.binance.com/api/v1/userDataStream

-4
source

Source: https://habr.com/ru/post/1691377/


All Articles