0

I am writing a laravel controller which calls Binance PHP APIs.

The PHP API works perfect if run individually from command line, e.g., php price.php

+++++++price.php++++++++

$api = new \Binance\API($api_key, $api_secret);

// Get all of your positions, including estimated BTC value $price =$api->price("BNBBTC"); print_r($price);

+++++++price.php+++++++++

However, if I call the api funcion price() from laravel controller, nothing shows up, no errors etc. I can dd($binance_api) and it returned the object is created successfully with all the correct API key/secret.

Class PriceController extends Controller{
public function price (Request $request){

$api_key = "xxxxxxx";

$api_secret = "xxxxxxxx";

$binance_api = new \Binance\API($api_key, $api_secret);

$price = $binance_api->price("BNBBTC");

}

}

1
  • in the API class definition, public function price() { return $this->priceData($this->httpRequest("v3/ticker/price")); } Commented Jan 22, 2019 at 19:43

1 Answer 1

1

You need to return a value

Class PriceController extends Controller{
  public function price (Request $request){
    $api_key = "xxxxxxx";
    $api_secret = "xxxxxxxx";
    $binance_api = new \Binance\API($api_key, $api_secret);
    $price = $binance_api->price("BNBBTC");
    return $price;
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

i found the rootcause was something else. But thank you for the comment.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.