I'm using the following library on Github
I need to get the order book from GDAX. I do this by doing the following:
$getOrderBook = $exchange->getOrderBook($exchangeProduct);
echo '<pre>';
print_r($getOrderBook);
echo '<pre>';
Using the above I only get Level 1 which according to GDAX I'll get the "Only the best bid and ask" and the output is something like this:
Array
(
[sequence] => 2402392394
[bids] => Array
(
[0] => Array
(
[0] => 3857.13
[1] => 0.14
[2] => 1
)
)
[asks] => Array
(
[0] => Array
(
[0] => 3859.99
[1] => 0.0475099
[2] => 2
)
)
The documentation states that "By default, only the inside (i.e. best) bid and ask are returned. This is equivalent to a book depth of 1 level. If you would like to see a larger order book, specify the level query parameter."
The documentation states also states that level 2 gets the "Top 50 bids and asks (aggregated)", and level 3 get the "Full order book (non aggregated)".
The class on Github contains the following code that relates to my query:
public function getOrderBook($product = 'BTC-USD') {
//$this->validate('product', $product);
return $this->request('book', array('id' => $product));
}
and for 'book':
public $endpoints = array(
'book' => array('method' => 'GET', 'uri' => '/products/%s/book'),
);
Now I would like to call my function $getOrderBook = $exchange->getOrderBook($exchangeProduct)
for level 2 or 3.
How can I do this without modifying the code I imported from Github, please?
Using a URL the output should be as follows:
https://api.gdax.com/products/BTC-EUR/book?level=2
Thanks.
I'm afraid the only way to do this is to extend the class and override the relevant methods.
Currently the URI specified in the
$endpoints
property is filled by thegetEndpoint
method. That's filling the%s
you mentioned in the title of your question. You can extend this class and override that method:Then you will also have to override the
orderBook
method:Alternatively you can submit a pull request to the Github library adjusting the code to support
level
.