我使用此代码从cex.io获取余额,它的工作原理为gr8:
$bal = json_encode($api -> balance());
$bald = json_decode($bal);
我得到了结果:
<?php echo json_decode($bald->BTC->available); ?>
事情是......我不能让自动收报机工作。这是cex.io的例子,它的进展顺利,但我只是想得到第一个报价:
var_dump($api -> ticker('GHS/BTC'));
结果
{'timestamp': '1383378967', 'bids': [['1.7', '0.30100000'], ['1.67', '0.00011000'], ['0.8', '0.02070000'], ['0.1002', '0.27748002'], ['0.1', '0.10000000'], ['0.011', '0.30500000'], ['0.009', '1.00000000'], ['0.00171', '0.00100000'], ['0.0012', '1.00000000'], ['0.00116819', '0.50000000'], ['0.001002', '33.00000000'], ['0.001001', '53.00000000'], ['0.001', '3.00000000'], ['0.00097626', '36.00000000'], ['0.0006', '85.00000000'], ['0.00058409', '0.50000000'], ['0.0004889', '0.06823960'], ['0.0003', '1.00000000'], ['0.00029204', '0.90000000'], ['0.0001', '101.00000000']], 'asks': []}
所以更准确。我想要的是'出价'('1.7','0.30100000')的第一个报价,以及'问'的第一个报价,我不知道如何得到它们。
我尝试了这个:
$tick = json_encode($api -> ticker('GHS/BTC'));
$tickd = json_decode($tick->bids);
和
$tickd = json_decode($tick->bids[0]);
$tickd = json_decode($tick->bids->[0]);
我是一个菜鸟,所以我一遍又一遍地尝试这个2天,我的头吸烟! 请帮助!!
答案 0 :(得分:0)
$tick = json_encode($api -> ticker('GHS/BTC'));
$bids = $tick["bids"];
$first_bid = isset($bids[0]) ? $bids[0] : null;
$asks = $tick["asks"];
$first_ask = isset($asks[0]) ? $asks[0] : null;