1

Im learning coinbase api and messing around with php. I cant seem to add data as variable from array as array is private. How can i set private values as variable?

$coinbaseconf = Configuration::apiKey($coinbaseapi, $coinbasesecret); $client = Client::create($coinbaseconf);

returns

Coinbase\Wallet\Value\Money Object ( [amount:Coinbase\Wallet\Value\Money:private] => 5567.17 [currency:Coinbase\Wallet\Value\Money:private] => GBP )

if i try:

$var1 = $btcusdsellprice->amount;

Get error

Fatal error: Uncaught Error: Cannot access private property Coinbase\Wallet\Value\Money::$amount in /var/www/html/xxx/xxx.php:22 Stack trace: #0 {main} thrown in /var/var/www/html/xxx.php on line 22

evenom
  • 13
  • 3

1 Answers1

1

It is not really clear what exactly you are trying to do but it could be the following:

use Coinbase\Wallet\Client;
use Coinbase\Wallet\Configuration;

$configuration = Configuration::apiKey($apiKey, $apiSecret);
// creating a client to communicate with the API
$client = Client::create($configuration);

//use the client to request data from the api
$sellPrice = $client->getSellPrice('BTC-USD');

For more information you should study the following resources:

rayphi
  • 503
  • 2
  • 14
  • 30
  • im trying to add $var1 = $btcusdsellprice->amount;. but cant as it returns private property that i cant assign to var. – evenom May 30 '18 at 11:22
  • 1
    Can you update your post with a more detailed code snippet? I can't figure out where your `$btcusdsellprice` comes from. – rayphi May 30 '18 at 14:20
  • the name of your variable says to me that you already did sth. like `$btcusdsellprice = $client->getSellPrice('BTC-USD');` so according to the [code](https://github.com/coinbase/coinbase-php/blob/master/src/Client.php#L121) you shoud get an object in `$btcusdsellprice` wich comes from following json https://api.coinbase.com/v2/prices/BTC-USD/sell (thats the api url of `getSellPrice('BTC-USD')`) --- so if you do it like this (because thats the only way to get sellprice of btcusd) it should work. – rayphi May 30 '18 at 14:51
  • im using coinbase php lib. – evenom Jun 06 '18 at 11:33
  • 1
    https://github.com/coinbase/coinbase-php <- I also assumed that you use that library! But this lib is a client to communicate with the [coinbase api](https://developers.coinbase.com/api/v2) – rayphi Jun 06 '18 at 12:26
  • as i was messing i realize that it wont be easy to make it do what i need, instead ill got to learn to work with coinbase api. side question have you worked with coinbase api and if yeah, how do you auth requests in php? – evenom Jun 06 '18 at 12:33
  • to use an [Official Client Library](https://developers.coinbase.com/api/v2#api-client-libraries) is usually the easiest way ;) so eventually you have to learn what exactly happens for example in the snippet above... – rayphi Jun 06 '18 at 12:45
  • I apologize for overlooking your question... If you only want to interact with your own account the easiest way is to use an api key... so the same way as in my Answer: > first define auth data `$configuration = Configuration::apiKey($apiKey, $apiSecret);` after that create a client with that data `$client = Client::create($configuration);` now you are so to say singed up. Every Request with `$client` is now authenticated for example `$user = $client->getUser($userId);` – rayphi Jun 07 '18 at 11:56