Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order book requests are not working #2

Closed
tistis96 opened this issue Jan 20, 2022 · 2 comments
Closed

Order book requests are not working #2

tistis96 opened this issue Jan 20, 2022 · 2 comments

Comments

@tistis96
Copy link

I have this code:

<?php
require __DIR__ . '/vendor/autoload.php';

use Soneso\StellarSDK\StellarSDK;
use Soneso\StellarSDK\Asset;

$sdk = StellarSDK::getPublicNetInstance();

$sellingAsset = Asset::createNonNativeAsset('yXLM', 'GARDNV3Q7YGT4AKSDF25LT32YSCCW4EV22Y2TV3I2PU2MMXJTEDL5T55');
$orderBook = $sdk->orderBook()->forBuyingAsset(Asset::native())->forSellingAsset($sellingAsset)->limit(1)->execute();
$offerAmount = $orderBook->getBids()->toArray()[0]->getAmount();
$offerPrice= $orderBook->getBids()->toArray()[0]->getPrice();

When I try to send a request to order book, I encounter this error:

PHP Fatal error: Uncaught Error: Typed property Soneso\StellarSDK\Responses\OrderBook\OrderBookResponse::$bids must not be accessed before initialization in C:\Users\USER\Desktop\projects\vendor\soneso\stellar-php-sdk\Soneso\StellarSDK\Responses\OrderBook\OrderBookResponse.php:50

The problem persist on getBids() method. I also ran the test from StellarSDKTests/TradesTest.php and it passes succesfully.

I'm using:

  • windows 10;
  • php version 8.1.1
christian-rogobete added a commit that referenced this issue Jan 20, 2022
@christian-rogobete
Copy link
Contributor

Hello @tistis96,
thank you for reporting this issue. I fixed it in this commit :0f7edb1
it is published in release 0.4.0
pls. update your sdk version and try again.

@danbradster
Copy link

danbradster commented Mar 15, 2022

That same code crashes with error 500 for me. I have my php file in the directory above /vendor/.

<?php
require __DIR__ . '/vendor/autoload.php';
//or this
//require 'vendor/autoload.php';

use Soneso\StellarSDK\StellarSDK;
use Soneso\StellarSDK\Asset;

$sdk = StellarSDK::getPublicNetInstance();

$sellingAsset = Asset::createNonNativeAsset('yXLM', 'GARDNV3Q7YGT4AKSDF25LT32YSCCW4EV22Y2TV3I2PU2MMXJTEDL5T55');
$orderBook = $sdk->orderBook()->forBuyingAsset(Asset::native())->forSellingAsset($sellingAsset)->limit(1)->execute();
$offerAmount = $orderBook->getBids()->toArray()[0]->getAmount();
$offerPrice= $orderBook->getBids()->toArray()[0]->getPrice();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants