创建交易机器人的例外

我正在尝试创建WordPress插件,该插件在PHP中为我的网站交易cryptocoins,并且我试图使用Bittrex API实现此目的。创建交易机器人的例外

我的问题是,当我尝试从API调用方法,引发异常。 有人可以帮我找到我的代码中的问题?

这里是主类中的代码,我从Client类创建一个对象。

require 'bittrex-master/src/edsonmedina/bittrex/Client.php'; 

use edsonmedina\bittrex\Client;

$keya = "xxx";

$secreta = "xxx";

$b = new Client ($keya, $secreta);

try{

$list = $b->getMarkets();

echo "$list";

}catch (Exception $e) {

echo 'Caught exception: ', $e->getMessage(), "\n";

}

echo "\n\n";

下面是代码从客户端类

namespace edsonmedina\bittrex; 

class Client

{

private $baseUrl;

private $apiVersion = 'v1.1';

private $apiKey;

private $apiSecret;

public function __construct ($apiKey, $apiSecret)

{

$this->apiKey = $apiKey;

$this->apiSecret = $apiSecret;

$this->baseUrl = 'https://bittrex.com/api/'.$this->apiVersion.'/';

}

/**

* Invoke API

* @param string $method API method to call

* @param array $params parameters

* @param bool $apiKey use apikey or not

* @return object

*/

private function call ($method, $params = array(), $apiKey = false)

{

$uri = $this->baseUrl.$method;

if ($apiKey == true) {

$params['apikey'] = $this->apiKey;

$params['nonce'] = time();

}

if (!empty($params)) {

$uri .= '?'.http_build_query($params);

}

$sign = hash_hmac ('sha512', $uri, $this->apiSecret);

$ch = curl_init ($uri);

curl_setopt ($ch, CURLOPT_HTTPHEADER, array('apisign: '.$sign));

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);

$result = curl_exec($ch);

$answer = json_decode($result);

if ($answer->success == false) {

throw new \Exception ($answer->message);

}

return $answer->result;

}

/**

* Get the open and available trading markets at Bittrex along with other meta data.

* @return array

*/

public function getMarkets()

{

return $this->call ('public/getmarkets');

}

回答:

根据您的意见和异常APIKEY_NOT_PROVIDEDcall方法的一部分,默认情况下你的APIKEY是假的。

return $this->call ('public/getmarkets', null, true); 

以上是 创建交易机器人的例外 的全部内容, 来源链接: utcz.com/qa/258054.html

回到顶部