PHP 使用 Coinbase API 来获取当前余额并列出账户中有哪些货币。它已经使用了几个星期,但是自从将一种货币换成 ETC(以太坊经典)后,余额忽略了这一点货币。它适用于我尝试过的所有其他货币,所以 ETC 的特别之处在于 Coinbase 没有通过 API 返回任何东西。 coinbase 网站组合确实正确报告了 ETC 余额,因此这绝对是 API 问题。
<?php
include 'cfg.php'; // Contains API key
require_once ('vendor/autoload.php'); // Loads the API libraries
use Coinbase\Wallet\Client as Client;
use Coinbase\Wallet\Configuration as Configuration;
use Coinbase\Wallet\Enum\Param;
use Coinbase\Wallet\Resource\Transaction;
$configuration = Configuration::apiKey($cbase_API_Key, $cbase_API_Secret);
$client = Client::create($configuration);
$stime = $client->getTime();
echo '<h2> Server Time ' . $stime['iso'] . '</h2>';
$balance = 0.00;
$accounts = $client->getAccounts(); // Get the account(s)
echo '<table>';
foreach ( $accounts as $acct )
{
$amt = $acct->getBalance()->getAmount() ;
echo '<tr>';
echo '<td>' . $acct->getCurrency() . '</td>';
echo '<td>' . $acct->getName() . '</td>';
echo '<td>' . $acct->getBalance()->getAmount() . '</td>';
echo '<td>' . $acct->getNativeBalance()->getAmount() . '</td>';
echo '</tr>';
$balance = $balance + $acct->getNativeBalance()->getAmount();
}
echo '<table>';
echo '<h2> Total Balance: ' . $balance . '</h2>';
?>
答案 0 :(得分:0)
问题归结为分页:
因此,修复方法是将分页限制设置为 100(允许的最大值)。
默认为 24,因此返回的列表不完整。
$accounts = $client->getAccounts(['limit' => 100]);