【问题标题】:Binance API call not working in Lavavel ControllerBinance API 调用在 Laravel 控制器中不起作用
【发布时间】:2019-06-16 08:13:35
【问题描述】:

我正在编写一个调用 Binance PHP API 的 laravel 控制器。

如果从命令行单独运行,PHP API 可以完美运行,例如, php价格.php

+++++++价格.php++++++++

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

// 获取你所有的仓位,包括估计的 BTC 价值 $price =$api->price("BNBBTC"); print_r($price);

+++++++价格.php+++++++++

但是,如果我从 laravel 控制器调用 api 函数 price(),则什么都没有显示,也没有错误等。我可以 dd($binance_api) 并且它返回的对象是使用所有正确的 API 密钥/秘密成功创建的。

类 PriceController 扩展了 Controller{
公共功能价格 (请求 $request){

$api_key = "xxxxxxx";

$api_secret = "xxxxxxxx";

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

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

}

}

【问题讨论】:

  • 在API类定义中,public function price() { return $this->priceData($this->httpRequest("v3/ticker/price")); }

标签: laravel binance


【解决方案1】:

你需要返回一个值

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;
  }
}

【讨论】:

  • 我发现根本原因是别的。不过谢谢你的评论。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-03-28
  • 2017-01-03
  • 2018-10-30
  • 1970-01-01
  • 1970-01-01
  • 2012-09-15
  • 2014-05-05
相关资源
最近更新 更多