0

所以我从 print_r 得到了下一个输出

Coinbase\Wallet\Value\Money Object
(
    [amount:Coinbase\Wallet\Value\Money:private] =>  18945.00
    [currency:Coinbase\Wallet\Value\Money:private] =>  USD
)

我正在使用 Coinbase SDK ->链接到 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);
}

任何帮助/想法将不胜感激,谢谢!

4

2 回答 2

1

一旦你得到了价值

$buyPrice = $client->getSpotPrice('BTC-USD');

然后您可以使用(来自源https://github.com/coinbase/coinbase-php/blob/master/src/Value/Money.php)...

$amount = $buyPrice->getAmount();
$currency = $buyPrice->getCurrency();
于 2017-12-17T15:38:06.833 回答
0
$BTCSellPrice = $client->getSpotPrice('BTC-USD');

//this is what you are looking for
$BTCUSD = $BTCSellPrice->getAmount();
于 2018-01-06T00:24:17.633 回答