简体   繁体   English

Coinbase API getBalance 忽略 ETC 货币

[英]Coinbase API getBalance ignoring ETC currency

The PHP uses the Coinbase API to get the current balance and list what currencies the account has money in. It has been used for a few weeks now, but since swapping one currency into ETC (Ethereum Classic), the balance ignores this currency. PHP 使用 Coinbase API 获取当前余额并列出该账户有哪些货币。它已经使用了几个星期,但是自从将一种货币换成 ETC(以太坊经典)后,余额忽略了这种货币。 It works for all other currencies I have tried, so what is special about ETC that Coinbase is not returing anything via the API.它适用于我尝试过的所有其他货币,所以 ETC 的特别之处在于 Coinbase 不会通过 API 退回任何东西。 The coinbase website portfolio does report the ETC balance correctly, so it's definitely a API issue. 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>';

?>

The issue came down to pagination:问题归结为分页:

The fix therefore was to set the pagination limit to 100 (max allowed).因此,解决方法是将分页限制设置为 100(允许的最大值)。

The default is 24, hence why the returned list was incomplete.默认值为 24,因此返回的列表不完整。

$accounts = $client->getAccounts(['limit' => 100]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM