exchange: handle escodex public api

disabled by default, edit settings table
This commit is contained in:
Sakda Chutchawan 2018-10-05 15:01:51 +07:00 committed by Tanguy Pruvot
parent 933e7a0257
commit 07277d9096
4 changed files with 78 additions and 1 deletions

View file

@ -15,6 +15,7 @@ function BackendPricesUpdate()
updatePoloniexMarkets();
updateBleutradeMarkets();
updateCryptoBridgeMarkets();
updateEscoDexMarkets();
updateGateioMarkets();
updateGraviexMarkets();
updateKrakenMarkets();
@ -370,6 +371,49 @@ function updateCryptoBridgeMarkets($force = false)
}
}
function updateEscoDexMarkets($force = false)
{
$exchange = 'escodex';
if (exchange_get($exchange, 'disabled')) return;
$count = (int) dboscalar("SELECT count(id) FROM markets WHERE name LIKE '$exchange%'");
if ($count == 0) return;
$result = escodex_api_query('ticker');
if(!is_array($result)) return;
foreach($result as $ticker)
{
if (is_null(objSafeVal($ticker,'id'))) continue;
#$pairs = explode('_', $ticker->id);
$symbol = $ticker->quote; $base = $ticker->base;
if($symbol == 'BTC' || $base != 'BTC') continue;
if (market_get($exchange, $symbol, "disabled")) {
$market->disabled = 1;
$market->message = 'disabled from settings';
}
$coin = getdbosql('db_coins', "symbol='{$symbol}'");
if(!$coin) continue;
if(!$coin->installed && !$coin->watch) continue;
$market = getdbosql('db_markets', "coinid={$coin->id} and name='{$exchange}'");
if(!$market) continue;
$price2 = ($ticker->highest_bid + $ticker->lowest_ask)/2;
$market->price2 = AverageIncrement($market->price2, $price2);
$market->price = AverageIncrement($market->price, $ticker->highest_bid);
$market->pricetime = time();
$market->priority = -1;
$market->txfee = 0.2; // trade pct
$market->save();
//debuglog("$exchange: update $symbol: {$market->price} {$market->price2}");
if ((empty($coin->price))||(empty($coin->price2))) {
$coin->price = $market->price;
$coin->price2 = $market->price2;
$coin->market = $exchange;
$coin->save();
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
function updateGateioMarkets($force = false)

View file

@ -14,6 +14,7 @@ function updateRawcoins()
exchange_set_default('coinbene', 'disabled', true);
exchange_set_default('coinexchange', 'disabled', true);
exchange_set_default('coinsmarkets', 'disabled', true);
exchange_set_default('escodex', 'disabled', true);
exchange_set_default('gateio', 'disabled', true);
exchange_set_default('jubi', 'disabled', true);
exchange_set_default('nova', 'disabled', true);
@ -219,6 +220,21 @@ function updateRawcoins()
}
}
if (!exchange_get('escodex', 'disabled')) {
$list = escodex_api_query('ticker');
if(is_array($list) && !empty($list))
{
dborun("UPDATE markets SET deleted=true WHERE name='escodex'");
foreach($list as $ticker) {
#debuglog (json_encode($ticker));
if (strtoupper($ticker->base) !== 'BTC')
continue;
$symbol = strtoupper($ticker->quote);
updateRawCoin('escodex', $symbol);
}
}
}
if (!exchange_get('hitbtc', 'disabled')) {
$list = hitbtc_api_query('symbols');
if(is_object($list) && isset($list->symbols) && is_array($list->symbols))
@ -464,7 +480,7 @@ function updateRawCoin($marketname, $symbol, $name='unknown')
}
// some other to ignore...
if (in_array($marketname, array('crex24','yobit','coinbene','kucoin','tradesatoshi')))
if (in_array($marketname, array('crex24','escodex','yobit','coinbene','kucoin','tradesatoshi')))
return;
if (market_get($marketname, $symbol, "disabled")) {

View file

@ -0,0 +1,14 @@
<?php
// http://labs.escodex.com/api/ticker
function escodex_api_query($method, $params='')
{
$uri = "http://labs.escodex.com/api/{$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);
$execResult = strip_tags(curl_exec($ch));
$obj = json_decode($execResult);
return $obj;
}

View file

@ -22,6 +22,7 @@ require_once("cexio.php");
require_once("coinbene.php");
require_once("crex24.php");
require_once("cryptobridge.php");
require_once("escodex.php");
require_once("gateio.php");
require_once("graviex.php");
require_once("kraken.php");
@ -112,6 +113,8 @@ function getMarketUrl($coin, $marketName)
$url = "https://c-cex.com/?p={$lowsymbol}-{$lowbase}";
else if($market == 'empoex')
$url = "http://www.empoex.com/trade/{$symbol}-{$base}";
else if($market == 'escodex')
$url = "https://wallet.escodex.com/market/ESCODEX.{$symbol}_ESCODEX.{$base}";
else if($market == 'gateio')
$url = "https://gate.io/trade/{$symbol}_{$base}";
else if($market == 'graviex')