2017-08-29 75 views
1

水平参数我使用Github如何使用与coinbase和GDAX

以下库我需要从GDAX的订单。我这样做,通过执行以下操作:

$getOrderBook = $exchange->getOrderBook($exchangeProduct); 
echo '<pre>'; 
print_r($getOrderBook); 
echo '<pre>'; 

使用上面我只得到1级,其根据GDAX我去拿“只有最好的买入价和卖出”,输出是这样的:

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 
       ) 

     ) 

该文档指出:“默认情况下,只返回内部(即最佳)出价和要价,相当于书籍深度为1级,如果您希望看到更大的订单,请指定级别查询参数“。

文档状态还指出,级别2获得“前50名出价和询问(汇总)”,级别3获得“全订单(非汇总)”。

在GitHub上类包含下面的代码,涉及到我的查询:

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

和“书”:

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

现在我想打电话给我的功能$getOrderBook = $exchange->getOrderBook($exchangeProduct) 2级或3.

如何在不修改从Github导入的代码的情况下执行此操作?

使用URL输出应该如下:

https://api.gdax.com/products/BTC-EUR/book?level=2

感谢。

+0

只是为了澄清,你在谈论https://docs.gdax.com/?php#get-product-order-book,对吧? – WOUNDEDStevenJones

+0

看起来像coinbase-exchange-php库可能没有实现层次(基于'$ endpoints'数组和'getOrderBook'方法没有'$ level'参数)。因此,如果不编辑github文件,我不确定它是否有可能,直到该库得到更新。 – WOUNDEDStevenJones

+0

也许可以使用这个库:https://gitlab.com/mrteye/GDAX。它似乎支持书籍级别。 – Aknosis

回答

0

恐怕唯一的办法就是这样做扩展类并覆盖相关的方法。

当前在$endpoints属性中指定的URI由getEndpoint方法填充。这填补了你在问题标题中提到的%s。您可以扩展此类并重写方法:

protected function getEndpoint($key, $params) { 
    // Check if the level has been specified and pull it from the $params 
    $level = null; 
    if (isset($params['level'])) { 
     $level = $params['level']; 
     unset($params['level']); 
    } 
    // Run the existing endpoint parse 
    $endpoint = parent::getEndpoint($key, $params); 
    // Add on the level 
    if ($level !== null) { 
     $endpoint['uri'] .= '?level='.$level; 
    } 

    return $endpoint 
} 

那么你也将不得不重写orderBook方法:

public function getOrderBook($product = 'BTC-USD', $level = null) { 
    return $this->request('book', array('id' => $product, 'level' => $level)); 
} 

另外,您可以提交pull请求到Github上库调整代码支持level

0

您可以覆盖终点,因为它宣布public

$exchange = new CoinbaseExchange; 
// ... 
$exchange->endpoints['book']['uri'] = '/products/%s/book?level=2'; 
$getOrderBook = $exchange->getOrderBook($exchangeProduct); 

虽然,这将会是最好创建为Scopey's answer建议扩展API公关。