Binance API密钥 [英] Binance API Keys

查看:935
本文介绍了Binance API密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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:

{代码":-2014,"msg":"API密钥格式无效."}

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

我正在使用的URL是这样的: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**

可以在此处找到Binance 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);

这篇关于Binance API密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆