add banx.io markets api

This commit is contained in:
Tanguy Pruvot 2015-07-12 15:33:16 +02:00
parent b1a4d9e57f
commit c3a70f8307
4 changed files with 101 additions and 12 deletions

View file

@ -4,8 +4,6 @@ function BackendPricesUpdate()
{
// debuglog(__FUNCTION__);
updateAlcurexMarkets();
updateCryptopiaMarkets();
updateBittrexMarkets();
updateCryptsyMarkets();
updateCCexMarkets();
@ -13,6 +11,10 @@ function BackendPricesUpdate()
updatePoloniexMarkets();
updateYobitMarkets();
updateJubiMarkets();
updateAlcurexMarkets();
updateCryptopiaMarkets();
updateBanxioMarkets();
$list2 = getdbolist('db_coins', "installed and symbol2 is not null");
foreach($list2 as $coin2)
@ -110,11 +112,11 @@ function getBestMarket($coin)
ORDER BY price DESC");
}
// note: you can add a record in market to hide this debug warning
if (!$market && $coin->enable)
if (!$market && empty($coin->market)) {
debuglog("best market for {$coin->symbol} is unknown");
//else
// debuglog("best market for {$coin->symbol} is {$market->name}");
$coin->market = 'unknown';
$coin->save();
}
return $market;
}
@ -582,7 +584,7 @@ function updateAlcurexMarkets()
$coin->price2 = $market->price2;
$coin->save();
}
// debuglog("alcurex update $coin->symbol: $market->price $market->price2");
// debuglog("alcurex: $pair $market->price ".bitcoinvaluetoa($market->price2));
}
}
}
@ -613,10 +615,44 @@ function updateCryptopiaMarkets()
$coin->price2 = $market->price2;
$coin->save();
}
// debuglog("cryptopia update $coin->symbol: $market->price $market->price2");
// debuglog("cryptopia: $pair $market->price ".bitcoinvaluetoa($market->price2));
break;
}
}
}
}
function updateBanxioMarkets()
{
$data = banx_public_api_query('getmarketsummaries');
if(!$data || !is_array($data->result)) return;
$list = getdbolist('db_markets', "name='banx'");
foreach($list as $market)
{
$coin = getdbo('db_coins', $market->coinid);
if(!$coin || !$coin->installed) continue;
$pair = strtoupper($coin->symbol).'-BTC';
foreach ($data->result as $ticker) {
if ($ticker->marketname === $pair) {
$market->price = AverageIncrement($market->price, $ticker->bid);
$market->price2 = AverageIncrement($market->price2, $ticker->last);
// debuglog("banx: $pair {$ticker->bid} {$ticker->last} => {$market->price} {$market->price2}");
if (intval($ticker->dayvolume) > 1)
$market->save();
if (empty($coin->price2)) {
$coin->price = $market->price;
$coin->price2 = $market->price2;
$coin->save();
}
if ($coin->name == 'unknown' && !empty($market->currencylong)) {
$coin->name = $market->currencylong;
$coin->save();
debuglog("banx: update $symbol name {$coin->name}");
}
break;
}
}
}
}

View file

@ -56,7 +56,7 @@ function updateRawcoins()
$res = yobit_api_query('info');
if($res)
{
dborun("update markets set deleted=true where name='yobit'");
dborun("UPDATE markets SET deleted=true WHERE name='yobit'");
foreach($res->pairs as $i=>$item)
{
$e = explode('_', $i);
@ -68,7 +68,7 @@ function updateRawcoins()
$list = cryptopia_api_query('GetMarkets');
if(isset($list->Data))
{
dborun("update markets set deleted=true where name='cryptopia'");
dborun("UPDATE markets SET deleted=true WHERE name='cryptopia'");
foreach($list->Data as $item) {
$e = explode('/', $item->Label);
if (strtoupper($e[1]) !== 'BTC')
@ -78,11 +78,10 @@ function updateRawcoins()
}
}
$list = alcurex_api_query('market','?info=on');
if(isset($list->MARKETS))
{
dborun("update markets set deleted=true where name='alcurex'");
dborun("UPDATE markets SET deleted=true WHERE name='alcurex'");
foreach($list->MARKETS as $item) {
$e = explode('_', $item->Pair);
$symbol = strtoupper($e[0]);
@ -90,6 +89,24 @@ function updateRawcoins()
}
}
$list = banx_simple_api_query('marketsv2');
if(isset($list) && is_array($list))
{
dborun("UPDATE markets SET deleted=true WHERE name='banx'");
foreach($list as $item) {
$e = explode('/', $item->market);
$base = strtoupper($e[1]);
if ($base != 'BTC')
continue;
$symbol = strtoupper($e[0]);
if ($symbol == 'ATP')
continue;
$name = explode('/',$item->marketname);
updateRawCoin('banx', $symbol, $name[0]);
//debuglog("banx: $symbol {$name[0]}");
}
}
//////////////////////////////////////////////////////////
dborun("delete from markets where deleted");

View file

@ -0,0 +1,35 @@
<?php
// https://www.banx.io/SimpleAPI?a=marketsv2
function banx_simple_api_query($method, $params='')
{
$uri = "https://www.banx.io/SimpleAPI?a=$method";
if (!empty($params))
$uri .= "&$params";
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$execResult = curl_exec($ch);
$obj = json_decode($execResult);
return $obj;
}
// https://www.banx.io/api/v2/public/getmarkets
function banx_public_api_query($method, $params='')
{
$uri = "https://www.banx.io/api/v2/public/$method";
if (!empty($params))
$uri .= "$params";
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$execResult = curl_exec($ch);
$obj = json_decode($execResult);
return $obj;
}

View file

@ -9,4 +9,5 @@ require_once("yobit.php");
require_once("jubi.php");
require_once("alcurex.php");
require_once("cryptopia.php");
require_once("banxio.php");