Skip to content

Commit

Permalink
Merge pull request #2700 from bziemek/ticker-apis
Browse files Browse the repository at this point in the history
More tickers
  • Loading branch information
TheSerapher committed Mar 18, 2018
2 parents 27388be + e0dc0cb commit a0f06e7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
56 changes: 44 additions & 12 deletions include/classes/tools.class.php
Expand Up @@ -44,9 +44,13 @@ public function getApi($url, $target, $auth=NULL) {
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
}
curl_setopt($ch, CURLOPT_URL, $url . $target);

$url = rtrim($url, '/');
$target = ltrim($target, '/');
curl_setopt($ch, CURLOPT_URL, $url . '/' . $target);
// curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
Expand All @@ -72,11 +76,9 @@ public function getApi($url, $target, $auth=NULL) {
**/
private function getApiType($url) {
if (preg_match('/coinchoose.com/', $url)) {
return 'coinchose';
} else if (preg_match('/btc-e.com/', $url)) {
return 'coinchoose';
} else if (preg_match('/btc-e.nz/', $url)) {
return 'btce';
} else if (preg_match('/cryptsy.com/', $url)) {
return 'cryptsy';
} else if (preg_match('/cryptopia.co.nz/', $url)) {
return 'cryptopia';
} else if (preg_match('/cryptorush.in/', $url)) {
Expand All @@ -87,6 +89,18 @@ private function getApiType($url) {
return 'c-cex';
} else if (preg_match('/bittrex.com/', $url)) {
return 'bittrex';
} else if (preg_match('/crypto-bridge.org/', $url)) {
return 'cryptobridge';
} else if (preg_match('/yobit.net/', $url)) {
return 'yobit';
} else if (preg_match('/binance.com/', $url)) {
return 'binance';
} else if (preg_match('/southxchange.com/', $url)) {
return 'southxchange';
} else if (preg_match('/mercatox.com/', $url)) {
return 'mercatox';
} else if (preg_match('/tradeogre.com/', $url)) {
return 'tradeogre';
}
$this->setErrorMessage("API URL unknown");
return false;
Expand All @@ -97,30 +111,28 @@ private function getApiType($url) {
**/
public function getPrice() {
$aData = $this->getApi($this->config['price']['url'], $this->config['price']['target']);
$strCurrency = $this->config['currency'];
$strBase = $this->config['currency'];
$strQuote = $this->config['price']['currency'];
// Check the API type for configured URL
if (!$strApiType = $this->getApiType($this->config['price']['url']))
return false;
// if api data is valid, extract price depending on API type
if (is_array($aData)) {
switch ($strApiType) {
case 'coinchose':
case 'coinchoose':
foreach ($aData as $aItem) {
if($strCurrency == $aItem[0])
if($strBase == $aItem[0])
return $aItem['price'];
}
break;
case 'btce':
return $aData['ticker']['last'];
break;
case 'cryptsy':
return @$aData['return']['markets'][$strCurrency]['lasttradeprice'];
break;
case 'cryptopia':
return @$aData['Data']['LastPrice'];
break;
case 'cryptorush':
return @$aData["$strCurrency/" . $this->config['price']['currency']]['last_trade'];
return @$aData["{$strBase}/{$strQuote}"]['last_trade'];
break;
case 'mintpal':
return @$aData['0']['last_price'];
Expand All @@ -131,6 +143,26 @@ public function getPrice() {
case 'bittrex':
return @$aData['result']['Last'];
break;
case 'cryptobridge':
foreach ($aData as $aItem) {
if("{$strBase}_{$strQuote}" == $aItem['id'])
return $aItem['last'];
}
case 'yobit':
return @$aData[strtolower($strBase) . "_" . strtolower($strQuote)]['last'];
break;
case 'binance':
return @$aData['price'];
break;
case 'southxchange':
return @$aData['Last'];
break;
case 'mercatox':
return @$aData['pairs']["{$strBase}_{$strQuote}"]['last'];
break;
case 'tradeogre':
return @$aData['price'];
break;
}
} else {
$this->setErrorMessage("Got an invalid response from ticker API");
Expand Down
2 changes: 1 addition & 1 deletion include/config/global.inc.dist.php
Expand Up @@ -113,7 +113,7 @@
* https://github.com/MPOS/php-mpos/wiki/Config-Setup#wiki-ticker-api
**/
$config['price']['enabled'] = false;
$config['price']['url'] = 'https://btc-e.com';
$config['price']['url'] = 'https://btc-e.nz';
$config['price']['target'] = '/api/2/ltc_usd/ticker';
$config['price']['currency'] = 'USD';

Expand Down

0 comments on commit a0f06e7

Please sign in to comment.