I am currently using Coinbase php API. I have try to buy ETH with the following code:
use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;
use Coinbase\Wallet\Resource;
use Coinbase\Wallet\Resource\Sell;
use Coinbase\Wallet\Resource\Buy;
use Coinbase\Wallet\Enum\Param;
use Coinbase\Wallet\Value\Money;
use Coinbase\Wallet\Resource\Account;
use Coinbase\Wallet\Enum\CurrencyCode;
use Coinbase\Wallet\Exception;
use GuzzleHttp\Exception\ClientException;
use Coinbase\Wallet\Resource\Transaction;
$configuration = Configuration::apiKey($apiKey, $apiSecret);
$client = Client::create($configuration);
$accounts = $client->getAccounts();
$account = $client->getPrimaryAccount(); // or some other account
$buy = new Buy([
'amount' => new Money(0.05, CurrencyCode::ETH),
'currency' => CurrencyCode::ETH
]);
$client->createAccountBuy($accounts, $buy, [Param::COMMIT => false]);
//$selldetail = $client->commitSell($sell);
$PaymentDetail = $client->decodeLastResponse();
//$PaymentArray = $PaymentDetail['data'];
echo '<pre>';
print_r($PaymentDetail);
echo '</pre>';
The code is throwing this error:
Message Uncaught TypeError: Argument 1 passed to Coinbase\Wallet\Client::createAccountBuy() must be an instance of Coinbase\Wallet\Resource\Account, instance of Coinbase\Wallet\Resource\ResourceCollection given, called in C:\xampp\htdocs\dev\coinbase\cb_coin.php on line 154 and defined in C:\xampp\htdocs\dev\coinbase\src\Client.php:421 Stack trace: #0 C:\xampp\htdocs\dev\coinbase\cb_coin.php(154): Coinbase\Wallet\Client->createAccountBuy(Object(Coinbase\Wallet\Resource\ResourceCollection), Object(Coinbase\Wallet\Resource\Buy), Array) #1 {main} thrown