markets: bit-z ticker api (#288)

This commit is contained in:
phm87 2018-08-10 14:42:42 +02:00 committed by Tanguy Pruvot
parent b39da19858
commit c25d7b9b77
5 changed files with 81 additions and 1 deletions

View file

@ -11,6 +11,7 @@ function BackendPricesUpdate()
settings_prefetch_all();
updateBittrexMarkets();
updateBitzMarkets();
updatePoloniexMarkets();
updateBleutradeMarkets();
updateCryptoBridgeMarkets();
@ -288,6 +289,42 @@ function updateBleutradeMarkets()
}
/////////////////////////////////////////////////////////////////////////////////////////////
function updateBitzMarkets($force = false)
{
$exchange = 'bitz';
if (exchange_get($exchange, 'disabled')) return;
$markets = bitz_api_query('tickerall');
foreach($markets as $c => $ticker)
{
$pairs = explode('_', $c);
$symbol = strtoupper(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->bidPrice + $ticker->askPrice)/2;
$market->price2 = AverageIncrement($market->price2, $price2);
$market->price = AverageIncrement($market->price, $ticker->bidPrice);
$market->pricetime = time();
$market->priority = -1;
$market->txfee = 0.2; // trade pct
$market->save();
// debuglog("$exchange: update $symbol: {$market->price} {$market->price2}");
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
function updateCryptoBridgeMarkets($force = false)

View file

@ -36,6 +36,19 @@ function updateRawcoins()
}
}
if (!exchange_get('bitz', 'disabled')) {
$list = bitz_api_query('tickerall');
dborun("UPDATE markets SET deleted=true WHERE name='bitz'");
foreach($list as $c => $ticker) {
$e = explode('_', $c);
if (strtoupper($e[1]) !== 'BTC')
continue;
$symbol = strtoupper($e[0]);
updateRawCoin('bitz', $symbol);
}
}
if (!exchange_get('bleutrade', 'disabled')) {
$list = bleutrade_api_query('public/getcurrencies');
if(isset($list->result) && !empty($list->result))
@ -417,7 +430,7 @@ function updateRawCoin($marketname, $symbol, $name='unknown')
}
}
if (in_array($marketname, array('nova','askcoin','binance','coinexchange','coinsmarkets','cryptobridge','hitbtc'))) {
if (in_array($marketname, array('nova','askcoin','binance','bitz','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,24 @@
<?php
// see https://apidoc.bit-z.com/en/Demo/PHP.html
// https://apiv2.bitz.com/Market/ticker?symbol=ltc_btc
// https://apiv2.bitz.com/Market/tickerall
function bitz_api_query($method, $params='', $returnType='object')
{
$url = "https://apiv2.bitz.com/Market/$method/";
if (!empty($params))
$url .= "?$params";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; BitZ API PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
curl_setopt($ch, CURLOPT_ENCODING , '');
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$execResult = curl_exec($ch);
if ($returnType == 'object')
$ret = json_decode($execResult);
else
$ret = json_decode($execResult,true);
return $ret->data;
}

View file

@ -15,6 +15,7 @@ function strip_data($data)
require_once("bitstamp.php");
require_once("bittrex.php");
require_once("bitz.php");
require_once("bleutrade.php");
require_once("ccexapi.php");
require_once("cexio.php");
@ -82,6 +83,8 @@ function getMarketUrl($coin, $marketName)
$url = "https://www.binance.com/trade.html?symbol={$symbol}_{$base}";
else if($market == 'bittrex')
$url = "https://bittrex.com/Market/Index?MarketName={$base}-{$symbol}";
else if($market == 'bitz')
$url = "https://www.bit-z.com/exchange/{$symbol}_{$base}";
else if($market == 'poloniex')
$url = "https://poloniex.com/exchange#{$lowbase}_{$lowsymbol}";
else if($market == 'bleutrade')

View file

@ -90,6 +90,9 @@ function runExchange($exchangeName=false)
doBittrexTrading(true);
updateBittrexMarkets();
break;
case 'bitz':
updateBitzMarkets();
break;
case 'cexio':
getCexIoBalances();