exchange: handle crex24 public api

This commit is contained in:
Tanguy Pruvot 2018-09-10 06:58:33 +02:00
parent b6aa81390a
commit 1c2a51394b
4 changed files with 105 additions and 3 deletions

View file

@ -20,6 +20,7 @@ function BackendPricesUpdate()
updateKrakenMarkets();
updateKuCoinMarkets();
updateCCexMarkets();
updateCrex24Markets();
updateCryptopiaMarkets();
updateHitBTCMarkets();
updateYobitMarkets();
@ -975,7 +976,65 @@ function updateAlcurexMarkets()
$coin->price2 = $market->price2;
$coin->save();
}
// debuglog("alcurex: $pair $market->price ".bitcoinvaluetoa($market->price2));
//debuglog("$exchange: $pair price updated to {$market->price}");
break;
}
}
}
}
function updateCrex24Markets()
{
$exchange = 'crex24';
if (exchange_get($exchange, 'disabled')) return;
$list = getdbolist('db_markets', "name LIKE '$exchange%'");
if (empty($list)) return;
$data = crex24_api_query('tickers');
if(!is_array($data)) return;
foreach($list as $market)
{
$coin = getdbo('db_coins', $market->coinid);
if(!$coin) continue;
$symbol = $coin->getOfficialSymbol();
$pair = strtoupper($symbol).'-BTC';
$sqlFilter = '';
if (!empty($market->base_coin)) {
$pair = strtoupper($symbol.'-'.$market->base_coin);
$sqlFilter = "AND base_coin='{$market->base_coin}'";
}
if (market_get($exchange, $symbol, "disabled")) {
$market->disabled = 1;
$market->message = 'disabled from settings';
$market->save();
continue;
}
foreach ($data as $ticker) {
if ($ticker->instrument === $pair) {
if ($market->disabled < 9) {
$nbm = (int) dboscalar("SELECT COUNT(id) FROM markets WHERE coinid={$coin->id} $sqlFilter");
$market->disabled = ($ticker->bid < $ticker->ask/2) && ($nbm > 1);
}
$price2 = ($ticker->bid+$ticker->ask)/2;
$market->price2 = AverageIncrement($market->price2, $price2);
$market->price = AverageIncrement($market->price, $ticker->bid);
$market->pricetime = time(); // $ticker->timestamp "2018-08-31T12:48:56Z"
$market->save();
if (empty($coin->price) && $ticker->ask) {
$coin->price = $market->price;
$coin->price2 = $price2;
$coin->save();
}
//debuglog("$exchange: $pair price updated to {$market->price}");
break;
}
}
}

View file

@ -38,7 +38,7 @@ function updateRawcoins()
if (!exchange_get('bitz', 'disabled')) {
$list = bitz_api_query('tickerall');
if (!empty($list)) {
dborun("UPDATE markets SET deleted=true WHERE name='bitz'");
foreach($list as $c => $ticker) {
$e = explode('_', $c);
@ -47,6 +47,7 @@ function updateRawcoins()
$symbol = strtoupper($e[0]);
updateRawCoin('bitz', $symbol);
}
}
}
if (!exchange_get('bleutrade', 'disabled')) {
@ -64,6 +65,19 @@ function updateRawcoins()
}
}
if (!exchange_get('crex24', 'disabled')) {
$list = crex24_api_query('currencies');
if(is_array($list) && !empty($list)) {
dborun("UPDATE markets SET deleted=true WHERE name='crex24'");
foreach ($list as $currency) {
$symbol = objSafeVal($currency, 'symbol');
$name = objSafeVal($currency, 'name');
if ($currency->isFiat || $currency->isDelisted) continue;
updateRawCoin('crex24', $symbol, $name);
}
}
}
if (!exchange_get('poloniex', 'disabled')) {
$poloniex = new poloniex;
$tickers = $poloniex->get_currencies();
@ -436,7 +450,7 @@ function updateRawCoin($marketname, $symbol, $name='unknown')
}
// some other to ignore...
if (in_array($marketname, array('yobit','kucoin','tradesatoshi')))
if (in_array($marketname, array('crex24','yobit','kucoin','tradesatoshi')))
return;
if (market_get($marketname, $symbol, "disabled")) {

View file

@ -0,0 +1,26 @@
<?php
// https://docs.crex24.com/trade-api/v2/
// https://api.crex24.com/v2/public/currencies
function crex24_api_query($method, $params='', $returnType='object')
{
$uri = "https://api.crex24.com/v2/public/{$method}";
if (!empty($params)) $uri .= "?{$params}";
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$execResult = strip_tags(curl_exec($ch));
if ($returnType == 'object')
$ret = json_decode($execResult);
else
$ret = json_decode($execResult,true);
return $ret;
}

View file

@ -19,6 +19,7 @@ require_once("bitz.php");
require_once("bleutrade.php");
require_once("ccexapi.php");
require_once("cexio.php");
require_once("crex24.php");
require_once("cryptobridge.php");
require_once("gateio.php");
require_once("graviex.php");
@ -97,6 +98,8 @@ function getMarketUrl($coin, $marketName)
$url = "https://www.coinexchange.io/market/{$symbol}/{$base}";
else if($market == 'coinsmarkets')
$url = "https://coinsmarkets.com/trade-{$base}-{$symbol}.htm";
else if($market == 'crex24')
$url = "https://crex24.com/exchange/{$symbol}-{$base}";
else if($market == 'cryptobridge')
$url = "https://wallet.crypto-bridge.org/market/BRIDGE.{$symbol}_BRIDGE.{$base}";
else if($market == 'cryptohub')