我试图使用以下Perl代码从Binance.com获取我的帐户信息:
#!/usr/bin/perl
use strict;
use warnings;
use Digest::SHA qw(hmac_sha256_hex);
use Time::HiRes qw(time);
my $api_key = "X";
my $api_secret = "X";
my $data = "recvWindow=2000×tamp=" . int(time() * 1000);
my $signature = uc(hmac_sha256_hex($data, $api_secret));
print `curl -s -m 3 -H 'X-MBX-APIKEY: $api_key' -d '$data&signature=$signature' -X GET 'https://api.binance.com/api/v3/account'` . "\n";
该代码看起来是正确的,应该可以工作,但我得到了以下错误:
{"code":-1102,"msg":"Mandatory parameter 'timestamp' was not sent, was empty/null, or malformed."}
当然,时间戳参数是发送的,不是空的或空的,也不是格式错误的。
如果我将输出打印到控制台,它将显示以下内容:
curl -s -m 3 -H 'X-MBX-APIKEY: X' -d 'recvWindow=2000×tamp=1516082731909&signature=X' -X GET 'https://api.binance.com/api/v3/account'
有人能帮忙吗?谢谢。
参考文献:
注意:我用'X‘替换了API密钥/秘密和签名
发布于 2018-01-16 07:37:19
对于
GET
端点,参数必须作为query string
发送。
基本上,使用GET
的目的是允许缓存响应,并且必须处理请求体会使这变得不必要地复杂。因此,GET
的主体请求应该总是被忽视,因此-d
对GET
请求没有任何意义。
您可以按照以下方式正确地形成URL:
use URI qw( );
my $url = URI->new('https://api.binance.com/api/v3/account');
$url->query_form(
recvWindow => 2000
timestamp => int(time() * 1000),
signature => uc(hmac_sha256_hex($data, $api_secret)),
);
您不仅仅是错误地构建了参数。您也有代码注入错误。可以正确地形成shell命令,如下所示:
use String::ShellQuote qw( shell_quote );
my $cmd = shell_quote(
'curl',
'-s',
'-m' => 3,
'-H' => 'X-MBX-APIKEY: $api_key',
'-X' => 'GET',
$url,
);
https://stackoverflow.com/questions/48275608
复制相似问题