我在获取bittrex帐户的余额时遇到问题:
$apikey='Removed';
$apisecret='Removed';
$nonce=time();
$uri='https://bittrex.com/api/v1.1/account/getbalances?apikey='.$apikey.'&nonce='.$nonce;
$sign=hash_hmac('sha512',$uri,$apisecret);
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisign:'.$sign));
$execResult = curl_exec($ch);
$data=file_get_contents( $execResult );
$json=json_decode( $data );
$result=$json->result;
foreach( $result as $i => $object ){
echo $object->Balance,'<br />';
}
它只提供以下JSON:
{
"success":true,
"message":"",
"result":[
{
"Currency":"ADA",
"Balance":1800.00000000,
"Available":1800.00000000,
"Pending":0.00000000,
"CryptoAddress":null
},
{
"Currency":"ARK",
"Balance":0.00000000,
"Available":0.00000000,
"Pending":0.00000000,
"CryptoAddress":null
},
{
"Currency":"BTC",
"Balance":0.00007135,
"Available":0.00007135,
"Pending":0.00000000,
"CryptoAddress":"XXX"
}
]
}
阅读一维数据,效果很好:
$btrxprice ="https://bittrex.com/api/v1.1/public/getticker?market=BTC-ETH";
$fgc = json_decode(file_get_contents($btrxprice), true);
$bidprice = $fgc["result"]["Bid"];
我的问题在哪里?我试图获得一个nth-coin的余额
答案 0 :(得分:0)
您似乎错过了CURLOPT_RETURNTRANSFER
。如果没有这个,响应机构根本不会回复给你。试试这个:
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisign:'.$sign));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
$json = json_decode($data);