coinbase-api - Coinbase API getBalance 忽略 ETC 货币
问题描述
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>';
?>
解决方案
问题归结为分页:
因此,解决方法是将分页限制设置为 100(允许的最大值)。
默认值为 24,因此返回的列表不完整。
$accounts = $client->getAccounts(['limit' => 100]);
推荐阅读
- php - PHP - 调整包含会话和重定向的代码
- bash - 获取运行的倒数第二个命令的退出代码状态
- docker - Flask Docker 容器 SocketIO 问题
- mysql - 使用 Ansible mysql_user 模块授予过程
- python - 一次循环遍历熊猫数据集
- python - 在 Pandas DataFrame 的不同列中查找最接近的先前值
- python - python3列表过滤器lambda获取TypeError:'wrapper_descriptor'对象不可下标
- swift - 动态字体大小缩放
- java - MongoDB Java Driver 4.1.1 如何配置超时设置
- reactjs - 在条件 HTML 链接上反应意外的令牌