Binance API Keys

前端 未结 6 1544
名媛妹妹
名媛妹妹 2021-02-16 00:20

I have set up a read-only API key on Binance to access account information like currency balances but I can\'t see the JSON data. The string query I put into the URL returns th

6条回答
  •  粉色の甜心
    2021-02-16 00:42

    You put it in the header. Following is tested working PHP example borrowed from jaggedsoft binance PHP library, it's a signed request that will return the account status.

    $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);
    

提交回复
热议问题