exchanges: drop allcoin, add safecex

RIP allcoin.com, welcome safecex!
This commit is contained in:
Tanguy Pruvot 2016-01-12 16:28:55 +01:00
parent 6fb14b3346
commit ee51f1936a
6 changed files with 52 additions and 88 deletions

View file

@ -49,7 +49,6 @@ class CoindbCommand extends CConsoleCommand
$nbUpdated = $this->grabBterIcons();
$nbUpdated += $this->grabCcexIcons();
$nbUpdated += $this->grabAllcoinIcons();
$nbUpdated += $this->grabCryptopiaIcons();
$nbUpdated += $this->grabAlcurexIcons();
$nbUpdated += $this->grabBanxIcons();
@ -289,42 +288,6 @@ class CoindbCommand extends CConsoleCommand
return $nbUpdated;
}
/**
* Icon grabber - Allcoin
*/
public function grabAllcoinIcons()
{
$url = 'http://www.allcoin.com/img/icon/';
$nbUpdated = 0;
$sql = "SELECT DISTINCT coins.id FROM coins INNER JOIN markets M ON M.coinid = coins.id ".
"WHERE M.name='allcoin' AND IFNULL(coins.image,'') = ''";
$coins = dbolist($sql);
if (empty($coins))
return 0;
echo "allcoin: try to download new icons...\n";
foreach ($coins as $coin) {
$coin = getdbo('db_coins', $coin["id"]);
$symbol = $coin->symbol;
if (!empty($coin->symbol2)) $symbol = $coin->symbol2;
$local = $this->basePath."/images/coin-{$symbol}.png";
try {
$data = @ file_get_contents($url.strtolower($symbol).'.png');
} catch (Exception $e) {
continue;
}
if (strlen($data) < 2048) continue;
echo $symbol." icon found\n";
file_put_contents($local, $data);
if (filesize($local) > 0) {
$coin->image = "/images/coin-{$symbol}.png";
$nbUpdated += $coin->save();
}
}
if ($nbUpdated)
echo "$nbUpdated icons downloaded from allcoin\n";
return $nbUpdated;
}
/**
* Icon grabber - Cryptsy (jpg only)
*/

View file

@ -8,13 +8,13 @@ function BackendPricesUpdate()
updatePoloniexMarkets();
updateBleutradeMarkets();
updateCCexMarkets();
updateCryptsyMarkets();
updateCryptopiaMarkets();
updateYobitMarkets();
updateAllcoinMarkets();
updateSafecexMarkets();
updateAlcurexMarkets();
updateBterMarkets();
updateEmpoexMarkets();
updateCryptsyMarkets();
updateJubiMarkets();
updateBanxioMarkets();
@ -683,34 +683,33 @@ function updateBanxioMarkets()
}
}
function updateAllcoinMarkets()
function updateSafecexMarkets()
{
$data = allcoin_api_query('pairs');
if(!is_object($data)) return;
$data = safecex_api_query('getmarkets');
if(empty($data)) return;
$list = getdbolist('db_markets', "name='allcoin'");
$list = getdbolist('db_markets', "name='safecex'");
foreach($list as $market)
{
$coin = getdbo('db_coins', $market->coinid);
if(!$coin || !$coin->installed) continue;
$pair = strtoupper($coin->symbol).'_BTC';
$pair = strtoupper($coin->symbol).'/BTC';
if (isset($data->data[$pair])) {
$ticker = $data->data[$pair];
$market->price = AverageIncrement($market->price, $ticker->top_bid);
$market->price2 = AverageIncrement($market->price2, $ticker->top_ask);
$market->deleted = (floatval($ticker->volume_24h_BTC) < 0.01);
$market->save();
if (empty($coin->price2)) {
$coin->price = $market->price;
$coin->price2 = $market->price2;
$coin->save();
}
if ($coin->name == 'unknown' && !empty($ticker->name)) {
$coin->name = $ticker->name;
$coin->save();
debuglog("allcoin: update $symbol name {$coin->name}");
foreach ($data as $ticker) {
if ($ticker->market === $pair) {
$price2 = ($ticker->bid + $ticker->ask)/2;
$market->price2 = AverageIncrement($market->price2, $price2);
$market->price = AverageIncrement($market->price, $ticker->bid*0.98);
$market->save();
if (empty($coin->price)) {
$coin->price = $market->price;
$coin->price2 = $market->price2;
$coin->save();
}
debuglog("safecex: $pair $market->price ".bitcoinvaluetoa($market->price2));
break;
}
}
}

View file

@ -85,16 +85,16 @@ function updateRawcoins()
}
}
$list = allcoin_api_query('pairs');
if(isset($list->data))
$list = safecex_api_query('getmarkets');
if(!empty($list))
{
dborun("UPDATE markets SET deleted=true WHERE name='allcoin'");
foreach($list->data as $pair => $item) {
if (strtoupper($item->exchange) !== 'BTC')
dborun("UPDATE markets SET deleted=true WHERE name='safecex'");
foreach($list as $pair => $item) {
$e = explode('/', $item->market);
if (strtoupper($e[1]) !== 'BTC')
continue;
if (intval($item->status) == -2)
continue;
updateRawCoin('allcoin', $item->type, $item->name);
$symbol = strtoupper($e[0]);
updateRawCoin('safecex', $symbol);
}
}

View file

@ -1,17 +0,0 @@
<?php
// https://www.allcoin.com/pub/api#market_summary
// https://www.allcoin.com/api2/pairs
function allcoin_api_query($method, $params='')
{
$uri = "https://www.allcoin.com/api2/{$method}{$params}";
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$execResult = strip_tags(curl_exec($ch));
$obj = json_decode($execResult);
return $obj;
}

View file

@ -1,12 +1,12 @@
<?php
require_once("cryptsy.php");
require_once("poloniex.php");
require_once("bittrex.php");
require_once("ccexapi.php");
require_once("bleutrade.php");
require_once("yobit.php");
require_once("allcoin.php");
require_once("cryptsy.php");
require_once("safecex.php");
require_once("bter.php");
require_once("empoex.php");
require_once("jubi.php");
@ -38,8 +38,8 @@ function getMarketUrl($coin, $marketName)
$url = "https://www.cryptopia.co.nz/Exchange?market={$symbol}_BTC";
else if($marketName == 'alcurex')
$url = "https://alcurex.org/index.php/crypto/market?pair={$lowsymbol}_btc";
else if($marketName == 'allcoin')
$url = "https://www.allcoin.com/trade/{$symbol}_BTC";
else if($marketName == 'safecex')
$url = "https://safecex.com/market?q={$symbol}/BTC";
else if($marketName == 'bter')
$url = "https://bter.com/trade/{$lowsymbol}_btc";
else if($marketName == 'banx')

View file

@ -0,0 +1,19 @@
<?php
// https://safecex.com/help/api
// https://safecex.com/api/getmarkets
// https://safecex.com/api/getmarket?market=VTC/BTC
function safecex_api_query($method, $params='')
{
$uri = "https://safecex.com/api/{$method}{$params}";
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$execResult = strip_tags(curl_exec($ch));
$obj = json_decode($execResult);
return $obj;
}