0

I am using the following Coinbase PHP api:

The class file includes the following line:

 * An array of API endpoints
 */
 public $endpoints = array(
 'book' => array('method' => 'GET', 'uri' => '/products/%s/book'),
 );

 public function getOrderBook($product = 'BTC-EUR') {
 //$this->validate('product', $product);
 return $this->request('book', array('id' => $product));
 }

In my file I call it using:

$exchange = new CoinbaseExchange();//Connect to Coinbase API
$getOrderbook = $exchange->getOrderBook();
print_r($getOrderbook);

Nothing is returned.

Though if I modify the class from:

'book' => array('method' => 'GET', 'uri' => '/products/%s/book'),

To:

'book' => array('method' => 'GET', 'uri' => '/products/%s/book?level=2'),

I get the desired out put in my file.

How can I leave the class as 'book' => array('method' => 'GET', 'uri' => '/products/%s/book'), as it is calling it through $getOrderbook = $exchange->getOrderBook();. Where do I include 'level=2` in the latter line please?

2 Answers 2

1

As the property $endpoints is public, you can access it from outside of class (see below):

$exchange = new CoinbaseExchange();//Connect to Coinbase API
$exchange->endpoints = array('book' => array('method' => 'GET', 'uri' => '/products/%s/book?level=2'))
$getOrderbook = $exchange->getOrderBook();
print_r($getOrderbook);
Sign up to request clarification or add additional context in comments.

4 Comments

You are replacing all endpoints and calling some other method may lead to error.
I have just tried to show that op can update $endpoint outside of class (I don't think it will lead to error). however op can only update the uri part, as you shown in your answer
I thought I could do something similar to this $getOrderbook = $exchange->getOrderBook([level=2);` but it didn't work
no that won't work, as it is not suppose to take endpoint as parameter
0

You can make temporary changes to endpoint:

$oldEndpoint= $exchange->endpoints['book']; // save previous value
$exchange->endpoints['book']['uri'] .= '?level=2'; // make needed changes
$exchange->getOrderBook();
$exchange->endpoints['book'] = $oldEndpoint; // reset to old value

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.