0
私のウェブサイトのcryptocoinsをPHPで取引しているWordPressプラグインを作成しようとしており、この目的で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";
はあなたの
call
方法であなたのAPIKEYが偽で、デフォルトではClientクラスコメントと例外
APIKEY_NOT_PROVIDED
を1として
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');
}
例外はありますか? – valtron
特定の例外はありません。唯一の出力は、「捕らえられた例外」です。予告が投げられた場合の出力です。 –
デバッグ!洞窟人に行って、例外がどこにあるかを見つけるためにprintステートメントを追加してください。 – zaph