MockingMagician / coinbase-pro-sdk

Coinbase Pro API SDK - Communicate easily with the Coinbase Pro API in PHP
https://mockingmagician.github.io/coinbase-pro-sdk/
MIT License
22 stars 8 forks source link

OrderBook level issue #23

Closed ghost closed 3 years ago

ghost commented 3 years ago

Hey! Thanks for this awesome API Wrapper, so far it has been very helpful in the development process.

Now the problem: I'm trying to understand how to read the order book from the API. I've found in the docs the following

$res = $this->api->products()->getProductOrderBook('BTC-USD')->getAsks();

but then it doesn't return an array nor an iterable object with the ask's order book. instead it returns:

array(1) {
  [0]=>
  object(MockingMagician\CoinbaseProSdk\Functional\DTO\OrderBookDetailsData)#46 (4) {
    ["price":"MockingMagician\CoinbaseProSdk\Functional\DTO\OrderBookDetailsData":private]=>
    float(57588.79)
    ["size":"MockingMagician\CoinbaseProSdk\Functional\DTO\OrderBookDetailsData":private]=>
    float(0.08184382)
    ["numOrders":"MockingMagician\CoinbaseProSdk\Functional\DTO\OrderBookDetailsData":private]=>
    int(3)
    ["orderId":"MockingMagician\CoinbaseProSdk\Functional\DTO\OrderBookDetailsData":private]=>
    NULL
  }
}

Which seems not to be iterable (unless I'm not understanding how to iterate it), nor useful for calculations. I've also read the docs stating something about the "levels" but I don't find documentation stating what does a level mean and how can it be used.

My use case is quite simple, I just need to use the order book to know what's the price I have to pay to buy x amount of the product.

Thank you very much for your time in reviewing this issue!

ghost commented 3 years ago

I've found the bug that was making this happen, the problem seems to be that the $level variable was orphan and not used within the function.

I've fixed it and made a pull request to your repository.

MockingMagician commented 3 years ago

Thanks for reporting, I will close after merge of #24

MockingMagician commented 3 years ago

Done :tada: #24 Commit b2f3a05

Thanks to @sm4rtk1dz

ghost commented 3 years ago

Nice!! thank you for this awesome wrapper, are changes already available on Composer?

MockingMagician commented 3 years ago

@sm4rtk1dz yes it is :smiley: last release v0.9.4

zenichanin commented 3 years ago

Hey @sm4rtk1dz and @MockingMagician, I am also having an issue with private properties. I'm simply trying to get historical data using getHistoricRates but all the properties (startTime, lowestPrice, highestPrice, etc.) are private. How can I use/save these values from the object? Kinda odd that they'd be private properties as is since it's simply historical data?

EDIT: After playing around with it a bit more, I see that I can get back a usable object by calling getCandles method on the results.

EDIT 2: Well I spoke too soon. Even though getCandles returns a seemingly normal object, each of the properties in it are also private and thus not accessible.

EDIT 3: My apologies for endless chain of edits, but I think I've figured it out. Essentially need to access each individual property using the getter methods such as $historic->getCandles()[0]->getLowestPrice()

MockingMagician commented 3 years ago

@zenichanin yes it is the way you will have to do it.

$historic->getCandles() is an iterable so you can access all candles if you iterate over it.

By the way, do not hesitate to launch a new issue if you have any question. Talking into a closed one might not be seen.