markets: handle cryptobridge ticker

This commit is contained in:
Tanguy Pruvot 2018-02-28 20:42:03 +01:00
parent 72b738da0d
commit 2dccc579cf
5 changed files with 87 additions and 4 deletions

View file

@ -13,6 +13,7 @@ function BackendPricesUpdate()
updateBittrexMarkets();
updatePoloniexMarkets();
updateBleutradeMarkets();
updateCryptoBridgeMarkets();
updateKrakenMarkets();
updateKuCoinMarkets();
updateCCexMarkets();
@ -283,6 +284,46 @@ function updateBleutradeMarkets()
/////////////////////////////////////////////////////////////////////////////////////////////
function updateCryptoBridgeMarkets($force = false)
{
$exchange = 'cryptobridge';
$result = cryptobridge_api_query('ticker');
if(!is_array($result)) return;
foreach($result as $ticker)
{
if (is_null(objSafeVal($ticker,'id'))) continue;
$pairs = explode('_', $ticker->id);
$symbol = reset($pairs); $base = end($pairs);
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->bid + $ticker->ask)/2;
$market->price2 = AverageIncrement($market->price2, $price2);
$market->price = AverageIncrement($market->price, $ticker->bid);
$market->pricetime = time();
$market->priority = -1;
$market->txfee = 0.2; // trade pct
$market->save();
//debuglog("$exchange: update $symbol: {$market->price} {$market->price2}");
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
function updateKrakenMarkets($force = false)
{
$exchange = 'kraken';

View file

@ -152,6 +152,21 @@ function updateRawcoins()
}
}
if (!exchange_get('cryptobridge', 'disabled')) {
$list = cryptobridge_api_query('ticker');
if(is_array($list) && !empty($list))
{
dborun("UPDATE markets SET deleted=true WHERE name='cryptobridge'");
foreach($list as $ticker) {
$e = explode('_', $ticker->id);
if (strtoupper($e[1]) !== 'BTC')
continue;
$symbol = strtoupper($e[0]);
updateRawCoin('cryptobridge', $symbol);
}
}
}
if (!exchange_get('hitbtc', 'disabled')) {
$list = hitbtc_api_query('symbols');
if(is_object($list) && isset($list->symbols) && is_array($list->symbols))
@ -375,7 +390,7 @@ function updateRawCoin($marketname, $symbol, $name='unknown')
}
}
if (in_array($marketname, array('nova','askcoin','binance','coinexchange','coinsmarkets','hitbtc'))) {
if (in_array($marketname, array('nova','askcoin','binance','coinexchange','coinsmarkets','cryptobridge','hitbtc'))) {
// don't polute too much the db with new coins, its better from exchanges with labels
return;
}

View file

@ -0,0 +1,20 @@
<?php
// https://api.crypto-bridge.org/api/v1/ticker
function cryptobridge_api_query($method, $params='')
{
$uri = "https://api.crypto-bridge.org/api/v1/{$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

@ -13,13 +13,14 @@ function strip_data($data)
return $out;
}
require_once("poloniex.php");
require_once("bitstamp.php");
require_once("bittrex.php");
require_once("ccexapi.php");
require_once("bleutrade.php");
require_once("ccexapi.php");
require_once("cexio.php");
require_once("cryptobridge.php");
require_once("kraken.php");
require_once("poloniex.php");
require_once("yobit.php");
require_once("shapeshift.php");
require_once("bter.php");
@ -89,7 +90,9 @@ function getMarketUrl($coin, $marketName)
else if($market == 'coinexchange')
$url = "https://www.coinexchange.io/market/{$symbol}/{$base}";
else if($market == 'coinsmarkets')
$url = " https://coinsmarkets.com/trade-{$base}-{$symbol}.htm";
$url = "https://coinsmarkets.com/trade-{$base}-{$symbol}.htm";
else if($market == 'cryptobridge')
$url = "https://wallet.crypto-bridge.org/market/BRIDGE.{$symbol}_BRIDGE.{$base}";
else if($market == 'cryptopia')
$url = "https://www.cryptopia.co.nz/Exchange?market={$symbol}_{$base}";
else if($market == 'cryptowatch')

View file

@ -78,6 +78,10 @@ function runExchange($exchangeName=false)
updateCryptopiaMarkets();
break;
case 'cryptobridge':
updateCryptoBridgeMarkets();
break;
case 'bitstamp':
getBitstampBalances();
break;