币安 API 密钥 [英] Binance API Keys
问题描述
我在 Binance 上设置了一个只读 API 密钥来访问账户信息,如货币余额,但我看不到 JSON 数据.我放入 URL 的字符串查询返回以下错误:
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 the following error:
{"code":-2014,"msg":"API 密钥格式无效."}
{"code":-2014,"msg":"API-key format invalid."}
我使用的网址是这样的:https://api.binance.com/api/v3/account?X-MBX-APIKEY=**key**&signature=**s-key**
The URL I am using is this: https://api.binance.com/api/v3/account?X-MBX-APIKEY=**key**&signature=**s-key**
币安 API 的文档可以在这里找到:https://www.binance.com/restapipub.html.我究竟做错了什么 ?
The documentation for Binance API can be found here: https://www.binance.com/restapipub.html. What am I doing wrong ?
推荐答案
你把它放在标题中.以下是从 jaggedsoft binance PHP 库借用的经过测试的 PHP 示例,它是一个签名请求,将返回帐户状态.
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);
这篇关于币安 API 密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!