php-coinbase/php-coinbase

PHP based coinbase api library

dev-master 2022-11-17 08:29 UTC

This package is auto-updated.

Last update: 2025-05-17 13:59:29 UTC


README

Unofficial sdk library for Coinbase. Note: This library is still in development.

For more information, please refer to the official documentation.

Installation

Install the library using Composer. Please read the Composer Documentation if you are unfamiliar with Composer or dependency managers in general.

"require": {
    "php-coinbase/php-coinbase": "dev-master"
}

Authentication

API Key

This library makes use of the API key authentication. Oauth2 authentication will be added in future.

use PHPCoinbase\PHPCoinbase;

// Setting your api keys
PHPCoinbase::setApiKey($apiKey);
PHPCoinbase::setApiSecret($apiSecret);

// OR

$phpcoinbase = new PHPCoinbase($apiKey, $apiSecret);

Responses

Each request returns a response object [PHPCoinbase\PHPCoinbaseResponse]. The response object contains three methods:

  • getStatus: 'OK'
  • getStatusCode: '200'
  • getData: {'data': 'my response'}

Usage

[Wallet API Endpoints]

$walletService = PHPCoinbase::useWalletsService();

Users resource

$usersResource = $walletService->users;

Show a user

$usersResource->getPublicUser('1a2b3c4d-5e6f7g8h-9i0j0k0l');

Show current user

$usersResource->getCurrentUser();

Show authorization information

$usersResource->getCurrentUserAuthInfo()

Update current user

[See: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-users#update-current-user]

$data = [
    'name' => 'My new name'
];
$usersResource->updateCurrentUser($data)

Accounts resource

$accountsResource = $walletsService->accounts;

List accounts

$accountsResource->listAccounts()

Update account

$accountsResource->updateAccount('account_id', 'name');

Show an account

$accountsResource->getAccount('account_id');

Delete account

$accountsResource->deleteAccount('account_id');

Addresses resource

$addressResource = $walletsService->address;

List addresses

$addressResource->listAddresses('account_id');

Show Address

$addressResource->getAddress('account_id', 'address_id');

List Transactions

$addressResource->listTransactions('account_id');

Create Address

$addressResource->createAddress('account_id', 'address_name');

Transactions resource

$transactionsResource = $walletsService->transactions;

List Transactions

$transactionsResource->listTransactions('account_id');

Show a Transaction

$transactionsResource->getTransaction('account_id', 'transaction_id');

Send Money

[See: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-transactions#send-money]

$data = [
    'to' => 'blockchain address or email',
    'amount' => 50
];
$transactionsResource->sendMoney('account_id', $data);

Transfer Money (between accounts)

[See: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-transactions#transfer-money-between-accounts]

$data = [
    'to' => 'to_account_id',
    'amount' => 50,
    'currency' => 'ETH'
];
$transactionsResource->transferMoneyBetweenAccounts('account_id', $data);

Request Money

[See: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-transactions#request-money]

$data = [
    'to' => 'to@email.com', // email
    'amount' => 50,
    'currency' => 'ETH'
];
$transactionsResource->requestMoney('account_id', $data);

Complete Request Money

$transactionsResource->completeRequestMoney('account_id', 'transaction_id');

Re-send Request Money

$transactionsResource->resendRequestMoney('account_id', 'transaction_id');

Cancel Request Money

$transactionsResource->cancelRequestMoney('account_id', 'transaction_id');

Buys resource

$buysResource = $walletsService->buys;

List buys

$buysResource->listBuys('account_id');

Show a buy

$buysResource->getBuy('account_id', 'buy_id');

Place buy order

$data = [
    'amount' => 50,
    'currency' => 'ETH'
];
$buysResource->placeBuyOrder('account_id', $data);

Commit a buy

$buysResource->commitBuy('account_id', 'buy_id');

Sells resource

$sellsResource = $walletsService->sells;

List sells

$sellsResource->listSells('account_id');

Show a sell

$sellsResource->getSell('account_id', 'sell_id');

Place sell order

[See: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-sells#place-sell-order]

$data = [
    'amount' => 50,
    'currency' => 'ETH'
];
$sellsResource->placeSellOrder('account_id', $data);

Commit a sell

$sellsResource->commitSell('account_id', 'sell_id');

Deposits resource

$depositsResource = $walletsService->deposits;

List Deposits

$depositsResource->listDeposits('account_id');

Show a Deposit

$depositsResource->getDeposit('account_id', 'deposit_id');

Deposit Funds

[See: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-deposits#deposit-funds]

$data = [
    'amount' => 50,
    'currency' => 'ETH',
    'payment_method' => 'payment_method_id' 
];
$depositsResource->depositFunds('account_id', $data);

Commit a Deposit

$depositsResource->commitDeposit('account_id', 'deposit_id');

Withdrawals resource

$withdrawalsResource = $walletsService->withdrawals;

List Withdrawals

$withdrawalsResource->listWithdrawals('account_id');

Show a Withdrawal

$withdrawalsResource->getWithdrawal('account_id', 'withdrawal_id');

Withdraw Funds

[See: https://docs.cloud.coinbase.com/sign-in-with-coinbase/docs/api-withdrawals#withdraw-funds]

$data = [
    'amount' => 50,
    'currency' => 'ETH',
    'payment_method' => 'payment_method_id' 
];
$withdrawalsResource->withdrawFunds('account_id', $data);

Commit a Withdrawal

$withdrawalsResource->commitWithdrawal('account_id', 'withdrawal_id');

Payment Methods resource

$paymentMethodsResource = $walletsService->paymentMethods;

List Payment Methods

$paymentMethodsResource->listPaymentMethods('account_id');

Show a Payment Method

$paymentMethodsResource->getPaymentMethod('account_id', 'payment_method_id');