所以我得到了print_r的下一个输出
Coinbase\Wallet\Value\Money Object
(
[amount:Coinbase\Wallet\Value\Money:private] => 18945.00
[currency:Coinbase\Wallet\Value\Money:private] => USD
)
我使用的是Coinbase SDK - > link to github
我的问题是我应该如何阅读金额值? 我正在使用
生成它$buyPrice = $client->getSpotPrice('BTC-USD');
和getSpotPrice函数是 - >
public function getSpotPrice($currency = null, array $params = [])
{
if (strpos($currency, '-') !== false) {
$pair = $currency;
} else if ($currency) {
$pair = 'BTC-' . $currency;
} else {
$pair = 'BTC-USD';
}
return $this->getAndMapMoney('/v2/prices/' . $pair . '/spot', $params);
}
在测试集成中看到类似的东西,但我无法告诉如何使这项工作:
public function testGetSpotPrice1()
{
$price = $this->client->getSpotPrice();
$this->assertInstanceOf(Money::class, $price);
}
任何帮助/想法将不胜感激,谢谢!
答案 0 :(得分:1)
一旦你获得了
的价值$buyPrice = $client->getSpotPrice('BTC-USD');
然后您可以使用(来自来源https://github.com/coinbase/coinbase-php/blob/master/src/Value/Money.php)...
$amount = $buyPrice->getAmount();
$currency = $buyPrice->getCurrency();
答案 1 :(得分:0)
$BTCSellPrice = $client->getSpotPrice('BTC-USD');
//this is what you are looking for
$BTCUSD = $BTCSellPrice->getAmount();