kraken: set a timeout to api calls

This commit is contained in:
Tanguy Pruvot 2016-03-30 18:04:32 +02:00
parent 87128640a3
commit 5f1779673d
2 changed files with 9 additions and 2 deletions

View file

@ -57,7 +57,8 @@ class ExchangeCommand extends CConsoleCommand
if (!empty(EXCH_BITTREX_KEY)) {
$balance = bittrex_api_query('account/getbalance','&currency=BTC');
echo("bittrex btc: ".json_encode($balance->result)."\n");
if (!is_object($balance)) echo "bittrex error\n";
else echo("bittrex btc: ".json_encode($balance->result)."\n");
}
if (!empty(EXCH_BLEUTRADE_KEY)) {
$balance = bleutrade_api_query('account/getbalances','&currencies=BTC');
@ -66,7 +67,7 @@ class ExchangeCommand extends CConsoleCommand
if (!empty(EXCH_BTER_KEY)) {
$info = bter_api_user('getfunds');
if (!$info || arraySafeVal($info,'result') != 'true' || !isset($info['available_funds'])) echo "error\n";
echo("bter available: ".json_encode($info['available_funds'])."\n");
else echo("bter available: ".json_encode($info['available_funds'])."\n");
}
if (!empty(EXCH_CCEX_KEY)) {
$ccex = new CcexAPI;

View file

@ -86,6 +86,9 @@ class KrakenAPI
curl_setopt($this->curl, CURLOPT_URL, $this->url . '/' . $this->version . '/public/' . $method);
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($this->curl, CURLOPT_HTTPHEADER, array());
curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($this->curl, CURLOPT_TIMEOUT, 20);
$result = curl_exec($this->curl);
if($result===false)
throw new KrakenAPIException('CURL error: ' . curl_error($this->curl));
@ -130,6 +133,9 @@ class KrakenAPI
curl_setopt($this->curl, CURLOPT_URL, $this->url . $path);
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($this->curl, CURLOPT_TIMEOUT, 20);
$result = curl_exec($this->curl);
if($result===false)
throw new KrakenAPIException('CURL error: ' . curl_error($this->curl));