From ee367bb570f8c13b47c80f95fab7ab2c989d3c79 Mon Sep 17 00:00:00 2001 From: lin <465382251@qq.com> Date: Fri, 26 Mar 2021 16:54:40 +0800 Subject: [PATCH] coinbase and coinbase pro --- README.md | 187 ++++++++++++++++- src/Api/Coinbase/Privates.php | 378 ++++++++++++++++++++++++++++++++++ src/Api/Coinbase/Publics.php | 71 +++++++ src/Coinbase.php | 21 +- src/Request.php | 23 ++- tests/coinbase/privates.php | 140 +++++++++++++ tests/coinbase/publics.php | 77 +++++++ 7 files changed, 887 insertions(+), 10 deletions(-) create mode 100644 src/Api/Coinbase/Privates.php create mode 100644 src/Api/Coinbase/Publics.php create mode 100644 tests/coinbase/privates.php create mode 100644 tests/coinbase/publics.php diff --git a/README.md b/README.md index 2e3a1b7..7142f4d 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,8 @@ composer require linwj/coinbase Support for more request Settings ```php +$coinbase=new Coinbase(); +//or $coinbase=new CoinbasePro(); //You can set special needs @@ -79,9 +81,186 @@ $coinbase->setOptions([ ]); ``` +### Coinbase Spot API + +Publics API [More](https://github.com/zhouaini528/coinbase-php/blob/master/tests/coinbase/publics.php) + +```php +$coinbase=new Coinbase(); + +try { + $result=$coinbase->publics()->getTime(); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +try { + $result=$coinbase->publics()->getCurrencies(); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +try { + $result=$coinbase->publics()->getExchangeRates(); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +try { + $result=$coinbase->publics()->getPricesBuy([ + 'currency_pair'=>'BTC-USD' + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +try { + $result=$coinbase->publics()->getPricesSell([ + 'currency_pair'=>'BTC-USD' + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +try { + $result=$coinbase->publics()->getPricesSpot([ + 'currency_pair'=>'BTC-USD' + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} +``` + +Privates API [More](https://github.com/zhouaini528/coinbase-php/blob/master/tests/coinbase/privates.php) +```php +//User +try { + $result=$coinbase->privates()->getUsers(); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +try { + $result=$coinbase->privates()->getUser([ + 'user_id'=>'fb352ff7-ce80-53ac-b0e1-7cfe51eca2ff' + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +try { + $result=$coinbase->privates()->getUserAuth(); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +try { + $result=$coinbase->privates()->putUser([ + 'name'=>'linwenjun' + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +//Accounts +try { + $result=$coinbase->privates()->getAccounts(); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +try { + $result=$coinbase->privates()->getAccount([ + 'account_id'=>'BTC' + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +try { + $result=$coinbase->privates()->putAccount([ + 'account_id'=>'BTC', + 'name'=>'bbttcc' + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +//Addresses +try { + $result=$coinbase->privates()->getAccountAddresses([ + 'account_id'=>'BTC' + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +//List transactions +try { + $result=$coinbase->privates()->getAccountTransactions([ + 'account_id'=>'b1096c85-fbf8-5293-9424-5af475446ebd' + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +//List buys +try { + $result=$coinbase->privates()->getAccountBuys([ + 'account_id'=>'b1096c85-fbf8-5293-9424-5af475446ebd' + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +try { + $result=$coinbase->privates()->getPaymentMethods(); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +//Place buy order +try { + $result=$coinbase->privates()->postAccountBuys([ + 'account_id'=>'b1096c85-fbf8-5293-9424-5af475446ebd', + 'amount'=>'1', + 'currency'=>'BTC', + //'payment_method'=>'83562370-3e5c-51db-87da-752af5ab9559', + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +``` + +[More Test](https://github.com/zhouaini528/coinbase-php/tree/master/tests/coinbase) + +[More Api](https://github.com/zhouaini528/coinbase-php/tree/master/src/Api/Coinbase) + + + + ### Coinbase Pro Spot API -Market related API [More](https://github.com/zhouaini528/coinbase-php/blob/master/tests/product.php) +Market related API [More](https://github.com/zhouaini528/coinbase-php/blob/master/tests/coinbase_pro/product.php) ```php $coinbase=new CoinbasePro(); @@ -112,7 +291,7 @@ try { ``` -Order related API [More](https://github.com/zhouaini528/coinbase-php/blob/master/tests/order.php) +Order related API [More](https://github.com/zhouaini528/coinbase-php/blob/master/tests/coinbase_pro/order.php) ```php $coinbase=new CoinbasePro($key,$secret,$passphrase); @@ -221,6 +400,6 @@ try { ``` -[More Test](https://github.com/zhouaini528/coinbase-php/tree/master/tests) +[More Test](https://github.com/zhouaini528/coinbase-php/tree/master/tests/coinbase_pro/) -[More Api](https://github.com/zhouaini528/coinbase-php/tree/master/src/Api) +[More Api](https://github.com/zhouaini528/coinbase-php/tree/master/src/Api/CoinbasePro/) diff --git a/src/Api/Coinbase/Privates.php b/src/Api/Coinbase/Privates.php new file mode 100644 index 0000000..4e7e660 --- /dev/null +++ b/src/Api/Coinbase/Privates.php @@ -0,0 +1,378 @@ + + * */ + +namespace Lin\Coinbase\Api\Coinbase; + +use Lin\Coinbase\Request; + +class Privates extends Request +{ + /** + *GET https://api.coinbase.com/v2/notifications + * */ + public function getNotifications(array $data=[]){ + $this->type='GET'; + $this->path='/v2/notifications'; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/notifications/:notifications_id + * */ + public function getNotification(array $data=[]){ + $this->type='GET'; + $this->path='/v2/notifications/'.$data['notifications_id']; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/users/:user_id + * */ + public function getUser(array $data=[]){ + $this->type='GET'; + $this->path='/v2/users/'.$data['user_id']; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/user + * */ + public function getUsers(array $data=[]){ + $this->type='GET'; + $this->path='/v2/user'; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/user/auth + * */ + public function getUserAuth(array $data=[]){ + $this->type='GET'; + $this->path='/v2/user/auth'; + $this->data=$data; + return $this->exec(); + } + + /** + *PUT https://api.coinbase.com/v2/user + * */ + public function putUser(array $data=[]){ + $this->type='PUT'; + $this->path='/v2/user'; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/accounts + * */ + public function getAccounts(array $data=[]){ + $this->type='GET'; + $this->path='/v2/accounts'; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/accounts/:account_id + * */ + public function getAccount(array $data=[]){ + $this->type='GET'; + $this->path='/v2/accounts/'.$data['account_id']; + $this->data=$data; + return $this->exec(); + } + + /** + *PUT https://api.coinbase.com/v2/accounts/:account_id + * */ + public function putAccount(array $data=[]){ + $this->type='PUT'; + $this->path='/v2/accounts/'.$data['account_id']; + $this->data=$data; + return $this->exec(); + } + + /** + *DELETE https://api.coinbase.com/v2/accounts/:account_id + * */ + public function deleteAccount(array $data=[]){ + $this->type='DELETE'; + $this->path='/v2/accounts/'.$data['account_id']; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/accounts/:account_id/addresses + * */ + public function getAccountAddresses(array $data=[]){ + $this->type='GET'; + $this->path='/v2/accounts/'.$data['account_id'].'/addresses'; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/accounts/:account_id/addresses/:address_id + * */ + public function getAccountAddress(array $data=[]){ + $this->type='GET'; + $this->path='/v2/accounts/'.$data['account_id'].'/addresses/'.$data['address_id']; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/accounts/:account_id/addresses/:address_id/transactions + * */ + public function getAccountAddressTransactions(array $data=[]){ + $this->type='GET'; + $this->path='/v2/accounts/'.$data['account_id'].'/addresses/'.$data['address_id'].'/transactions'; + $this->data=$data; + return $this->exec(); + } + + /** + *POST https://api.coinbase.com/v2/accounts/:account_id/addresses + * */ + public function postAccountAddresses(array $data=[]){ + $this->type='POST'; + $this->path='/v2/accounts/'.$data['account_id'].'/addresses'; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/accounts/:account_id/transactions + * */ + public function getAccountTransactions(array $data=[]){ + $this->type='GET'; + $this->path='/v2/accounts/'.$data['account_id'].'/transactions'; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/accounts/:account_id/transactions/:transaction_id + * */ + public function getAccountTransaction(array $data=[]){ + $this->type='GET'; + $this->path='/v2/accounts/'.$data['account_id'].'/transactions/'.$data['transaction_id']; + $this->data=$data; + return $this->exec(); + } + + /** + *POST https://api.coinbase.com/v2/accounts/:account_id/transactions/:transaction_id/complete + * */ + public function postAccountTransactionComplete(array $data=[]){ + $this->type='POST'; + $this->path='/v2/accounts/'.$data['account_id'].'/transactions/'.$data['transaction_id'].'/complete'; + $this->data=$data; + return $this->exec(); + } + + /** + *POST https://api.coinbase.com/v2/accounts/:account_id/transactions/:transaction_id/resend + * */ + public function postAccountTransactionResend(array $data=[]){ + $this->type='POST'; + $this->path='/v2/accounts/'.$data['account_id'].'/transactions/'.$data['transaction_id'].'/resend'; + $this->data=$data; + return $this->exec(); + } + + /** + *DELETE https://api.coinbase.com/v2/accounts/:account_id/transactions/:transaction_id + * */ + public function deleteAccountTransaction(array $data=[]){ + $this->type='DELETE'; + $this->path='/v2/accounts/'.$data['account_id'].'/transactions/'.$data['transaction_id']; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/accounts/:account_id/buys + * */ + public function getAccountBuys(array $data=[]){ + $this->type='GET'; + $this->path='/v2/accounts/'.$data['account_id'].'/buys'; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/accounts/:account_id/buys/:buy_id + * */ + public function getAccountBuyId(array $data=[]){ + $this->type='GET'; + $this->path='/v2/accounts/'.$data['account_id'].'/buys/'.$data['buy_id']; + $this->data=$data; + return $this->exec(); + } + + /** + *POST https://api.coinbase.com/v2/accounts/:account_id/buys + * */ + public function postAccountBuys(array $data=[]){ + $this->type='POST'; + $this->path='/v2/accounts/'.$data['account_id'].'/buys'; + $this->data=$data; + return $this->exec(); + } + + /** + *POST https://api.coinbase.com/v2/accounts/:account_id/buys/:buy_id/commit + * */ + public function get(array $data=[]){ + $this->type='GET'; + $this->path=''; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/accounts/:account_id/sells + * */ + public function getAccountSells(array $data=[]){ + $this->type='GET'; + $this->path='/v2/accounts/'.$data['account_id'].'/sells'; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/accounts/:account_id/sells/:sell_id + * */ + public function getAccountSell(array $data=[]){ + $this->type='GET'; + $this->path='/v2/accounts/'.$data['account_id'].'/sells/'.$data['sell_id']; + $this->data=$data; + return $this->exec(); + } + + /** + *POST https://api.coinbase.com/v2/accounts/:account_id/sells + * */ + public function postAccountSells(array $data=[]){ + $this->type='POST'; + $this->path='/v2/accounts/'.$data['account_id'].'/sells'; + $this->data=$data; + return $this->exec(); + } + /** + *POST https://api.coinbase.com/v2/accounts/:account_id/sells/:sell_id/commit + * */ + public function postAccountSellCommit(array $data=[]){ + $this->type='POST'; + $this->path='/v2/accounts/'.$data['account_id'].'/sells/'.$data['sell_id'].'/commit'; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/accounts/:account_id/deposits + * */ + public function getAccountDeposits(array $data=[]){ + $this->type='GET'; + $this->path='/v2/accounts/'.$data['account_id'].'/deposits'; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/accounts/:account_id/deposits/:deposit_id + * */ + public function getAccountDeposit(array $data=[]){ + $this->type='GET'; + $this->path='/v2/accounts/'.$data['account_id'].'/deposits/'.$data['deposit_id']; + $this->data=$data; + return $this->exec(); + } + + /** + *POST https://api.coinbase.com/v2/accounts/:account_id/deposits + * */ + public function postAccountDeposits(array $data=[]){ + $this->type='POST'; + $this->path='/v2/accounts/'.$data['account_id'].'/deposits'; + $this->data=$data; + return $this->exec(); + } + /** + *POST https://api.coinbase.com/v2/accounts/:account_id/deposits/:deposit_id/commit + * */ + public function postAccountDepositCommit(array $data=[]){ + $this->type='POST'; + $this->path='/v2/accounts/'.$data['account_id'].'/deposits/'.$data['deposit_id'].'/commit'; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/accounts/:account_id/withdrawals + * */ + public function getAccountWithdrawals(array $data=[]){ + $this->type='GET'; + $this->path='/v2/accounts/'.$data['account_id'].'/withdrawals'; + $this->data=$data; + return $this->exec(); + } + /** + *GET https://api.coinbase.com/v2/accounts/:account_id/withdrawals/:withdrawal_id + * */ + public function getAccountWithdrawal(array $data=[]){ + $this->type='GET'; + $this->path='/v2/accounts/'.$data['account_id'].'/withdrawals/'.$data['withdrawal_id']; + $this->data=$data; + return $this->exec(); + } + + /** + *POST https://api.coinbase.com/v2/accounts/:account_id/withdrawals + * */ + public function postAccountWithdrawals(array $data=[]){ + $this->type='POST'; + $this->path='/v2/accounts/'.$data['account_id'].'/withdrawals'; + $this->data=$data; + return $this->exec(); + } + + /** + *POST https://api.coinbase.com/v2/accounts/:account_id/withdrawals/:withdrawal_id/commit + * */ + public function postAccountWithdrawalCommit(array $data=[]){ + $this->type='POST'; + $this->path='/v2/accounts/'.$data['account_id'].'/withdrawals/'.$data['withdrawal_id'].'/commit'; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/payment-methods + * */ + public function getPaymentMethods(array $data=[]){ + $this->type='GET'; + $this->path='/v2/payment-methods'; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/payment-methods/:payment_method_id/ + * */ + public function getPaymentMethod(array $data=[]){ + $this->type='GET'; + $this->path='/v2/payment-methods/'.$data['payment_method_id']; + $this->data=$data; + return $this->exec(); + } +} diff --git a/src/Api/Coinbase/Publics.php b/src/Api/Coinbase/Publics.php new file mode 100644 index 0000000..9f1e056 --- /dev/null +++ b/src/Api/Coinbase/Publics.php @@ -0,0 +1,71 @@ + + * */ + +namespace Lin\Coinbase\Api\Coinbase; + +use Lin\Coinbase\Request; + +class Publics extends Request +{ + /** + *GET https://api.coinbase.com/v2/currencies + * */ + public function getCurrencies(array $data=[]){ + $this->type='GET'; + $this->path='/v2/currencies'; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/exchange-rates + * */ + public function getExchangeRates(array $data=[]){ + $this->type='GET'; + $this->path='/v2/exchange-rates'; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/prices/:currency_pair/buy + * */ + public function getPricesBuy(array $data=[]){ + $this->type='GET'; + $this->path='/v2/prices/'.$data['currency_pair'].'/buy'; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/prices/:currency_pair/sell + * */ + public function getPricesSell(array $data=[]){ + $this->type='GET'; + $this->path='/v2/prices/'.$data['currency_pair'].'/sell'; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/prices/:currency_pair/spot + * */ + public function getPricesSpot(array $data=[]){ + $this->type='GET'; + $this->path='/v2/prices/'.$data['currency_pair'].'/spot'; + $this->data=$data; + return $this->exec(); + } + + /** + *GET https://api.coinbase.com/v2/time + * */ + public function getTime(array $data=[]){ + $this->type='GET'; + $this->path='/v2/time'; + $this->data=$data; + return $this->exec(); + } +} diff --git a/src/Coinbase.php b/src/Coinbase.php index eff35e2..4548247 100644 --- a/src/Coinbase.php +++ b/src/Coinbase.php @@ -5,16 +5,18 @@ namespace Lin\Coinbase; +use Lin\Coinbase\Api\Coinbase\Publics; +use Lin\Coinbase\Api\Coinbase\Privates; + class Coinbase { protected $key; protected $secret; - protected $passphrase; protected $host; protected $options=[]; - function __construct(string $key='',string $secret='',string $host='https://api.pro.coinbase.com'){ + function __construct(string $key='',string $secret='',string $host='https://api.coinbase.com'){ $this->key=$key; $this->secret=$secret; $this->host=$host; @@ -27,7 +29,6 @@ private function init(){ return [ 'key'=>$this->key, 'secret'=>$this->secret, - 'passphrase'=>$this->passphrase, 'host'=>$this->host, 'options'=>$this->options, @@ -42,4 +43,18 @@ private function init(){ function setOptions(array $options=[]){ $this->options=$options; } + + /** + * + * */ + function publics(){ + return new Publics($this->init()); + } + + /** + * + * */ + function privates(){ + return new Privates($this->init()); + } } diff --git a/src/Request.php b/src/Request.php index 1855780..221089f 100644 --- a/src/Request.php +++ b/src/Request.php @@ -86,7 +86,16 @@ protected function signature(){ $plain = $this->nonce . $path . $body; - $this->signature = base64_encode(hash_hmac('sha256', $plain, base64_decode($this->secret), true)); + switch ($this->platform){ + case 'coinbase':{ + $this->signature = hash_hmac('sha256', $plain, $this->secret); + break; + } + case 'coinbasepro':{ + $this->signature = base64_encode(hash_hmac('sha256', $plain, base64_decode($this->secret), true)); + break; + } + } } /** @@ -95,12 +104,20 @@ protected function signature(){ protected function headers(){ $this->headers= [ 'Content-Type' => 'application/json', - 'CB-ACCESS-KEY' => $this->key, 'CB-ACCESS-SIGN' => $this->signature, 'CB-ACCESS-TIMESTAMP' => $this->nonce, - 'CB-ACCESS-PASSPHRASE' => $this->passphrase, ]; + switch ($this->platform){ + case 'coinbase':{ + $this->headers['CB-VERSION']=date('Y-m-d',time()); + break; + } + case 'coinbasepro':{ + $this->headers['CB-ACCESS-PASSPHRASE']=$this->passphrase; + break; + } + } } /** diff --git a/tests/coinbase/privates.php b/tests/coinbase/privates.php new file mode 100644 index 0000000..15530bc --- /dev/null +++ b/tests/coinbase/privates.php @@ -0,0 +1,140 @@ + + * */ + +use Lin\Coinbase\Coinbase; + +require __DIR__ .'../../../vendor/autoload.php'; + +include 'ket_secret.php'; + +$coinbase=new Coinbase($key,$secret); + +//You can set special needs +$coinbase->setOptions([ + //Set the request timeout to 60 seconds by default + 'timeout'=>10, + + //If you are developing locally and need an agent, you can set this + //'proxy'=>true, + //More flexible Settings + /* 'proxy'=>[ + 'http' => 'http://127.0.0.1:12333', + 'https' => 'http://127.0.0.1:12333', + 'no' => ['.cn'] + ], */ + //Close the certificate + //'verify'=>false, +]); + +//User +try { + $result=$coinbase->privates()->getUsers(); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +try { + $result=$coinbase->privates()->getUser([ + 'user_id'=>'fb352ff7-ce80-53ac-b0e1-7cfe51eca2ff' + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +try { + $result=$coinbase->privates()->getUserAuth(); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +try { + $result=$coinbase->privates()->putUser([ + 'name'=>'linwenjun' + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +//Accounts +try { + $result=$coinbase->privates()->getAccounts(); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +try { + $result=$coinbase->privates()->getAccount([ + 'account_id'=>'BTC' + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +try { + $result=$coinbase->privates()->putAccount([ + 'account_id'=>'BTC', + 'name'=>'bbttcc' + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +//Addresses +try { + $result=$coinbase->privates()->getAccountAddresses([ + 'account_id'=>'BTC' + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +//List transactions +try { + $result=$coinbase->privates()->getAccountTransactions([ + 'account_id'=>'b1096c85-fbf8-5293-9424-5af475446ebd' + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +//List buys +try { + $result=$coinbase->privates()->getAccountBuys([ + 'account_id'=>'b1096c85-fbf8-5293-9424-5af475446ebd' + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +try { + $result=$coinbase->privates()->getPaymentMethods(); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +//Place buy order +try { + $result=$coinbase->privates()->postAccountBuys([ + 'account_id'=>'b1096c85-fbf8-5293-9424-5af475446ebd', + 'amount'=>'1', + 'currency'=>'BTC', + //'payment_method'=>'83562370-3e5c-51db-87da-752af5ab9559', + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} diff --git a/tests/coinbase/publics.php b/tests/coinbase/publics.php new file mode 100644 index 0000000..acfcfae --- /dev/null +++ b/tests/coinbase/publics.php @@ -0,0 +1,77 @@ + + * */ + +use Lin\Coinbase\Coinbase; + +require __DIR__ .'../../../vendor/autoload.php'; + +$coinbase=new Coinbase(); + +//You can set special needs +$coinbase->setOptions([ + //Set the request timeout to 60 seconds by default + 'timeout'=>10, + + //If you are developing locally and need an agent, you can set this + //'proxy'=>true, + //More flexible Settings + /* 'proxy'=>[ + 'http' => 'http://127.0.0.1:12333', + 'https' => 'http://127.0.0.1:12333', + 'no' => ['.cn'] + ], */ + //Close the certificate + //'verify'=>false, +]); + +try { + $result=$coinbase->publics()->getTime(); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +try { + $result=$coinbase->publics()->getCurrencies(); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +try { + $result=$coinbase->publics()->getExchangeRates(); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +try { + $result=$coinbase->publics()->getPricesBuy([ + 'currency_pair'=>'BTC-USD' + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +try { + $result=$coinbase->publics()->getPricesSell([ + 'currency_pair'=>'BTC-USD' + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} + +try { + $result=$coinbase->publics()->getPricesSpot([ + 'currency_pair'=>'BTC-USD' + ]); + print_r($result); +}catch (\Exception $e){ + print_r(json_decode($e->getMessage(),true)); +} +