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");

}

}

Community
  • 1
  • 1
GoQuestion
  • 71
  • 2
  • 9
  • in the API class definition, public function price() { return $this->priceData($this->httpRequest("v3/ticker/price")); } – GoQuestion Jan 22 '19 at 19:43

1 Answers1

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;
  }
}
cmac
  • 3,123
  • 6
  • 36
  • 49