markets: improve disabled flag

disabled = 9 means permanent disable by admin (no more checked)
else, values 1 to 8 will depends on different cases... api down, low volume, etc

for the moment, only handle the autoswitch between 0 and 1 when the api reports an active state
This commit is contained in:
Tanguy Pruvot 2016-03-28 18:08:16 +02:00
parent fbe8689fa1
commit 9f431ec275
3 changed files with 46 additions and 49 deletions

View file

@ -66,11 +66,7 @@ function BackendPricesUpdate()
$coin->price *= $base_coin->price; $coin->price *= $base_coin->price;
$coin->price2 *= $base_coin->price; $coin->price2 *= $base_coin->price;
} }
// if($market->name == 'c-cex')
// $coin->price *= 0.95;
} }
else else
{ {
$coin->price = 0; $coin->price = 0;
@ -160,25 +156,18 @@ function updateBleutradeMarkets()
} }
$market->txfee = $currency->TxFee; $market->txfee = $currency->TxFee;
if(!$currency->IsActive && !$market->disabled) if($market->disabled < 9) $market->disabled = !$currency->IsActive;
{
$market->price = 0;
$market->disabled = 1;
$market->save();
continue;
}
$market->save(); $market->save();
if($market->disabled) continue;
$pair = "{$coin->symbol}_BTC"; $pair = "{$coin->symbol}_BTC";
sleep(1); sleep(1);
$ticker = bleutrade_api_query('public/getticker', "&market=$pair"); $ticker = bleutrade_api_query('public/getticker', "&market=$pair");
if(!$ticker || !$ticker->success || !$ticker->result) continue; if(!$ticker || !$ticker->success || !$ticker->result) continue;
if ($market->price == 0 && $market->disabled) {
$market->disabled = 0;
}
$price2 = ($ticker->result[0]->Bid+$ticker->result[0]->Ask)/2; $price2 = ($ticker->result[0]->Bid+$ticker->result[0]->Ask)/2;
$market->price2 = AverageIncrement($market->price2, $price2); $market->price2 = AverageIncrement($market->price2, $price2);
$market->price = AverageIncrement($market->price, $ticker->result[0]->Bid); $market->price = AverageIncrement($market->price, $ticker->result[0]->Bid);
@ -279,15 +268,11 @@ function updateBittrexMarkets($force = false)
$market->txfee = $currency->TxFee; $market->txfee = $currency->TxFee;
$market->message = $currency->Notice; $market->message = $currency->Notice;
if(!$currency->IsActive) if($market->disabled < 9) $market->disabled = !$currency->IsActive;
{
$market->price = 0;
$market->save();
continue;
}
$market->save(); $market->save();
if($market->disabled) continue;
$pair = "BTC-$coin->symbol"; $pair = "BTC-$coin->symbol";
$ticker = bittrex_api_query('public/getticker', "&market=$pair"); $ticker = bittrex_api_query('public/getticker', "&market=$pair");
@ -407,13 +392,10 @@ function updateCryptsyMarkets()
break; break;
} }
$market->disabled = (int) (arraySafeVal($currency,'maintenancemode',0) > 0);
$market->save(); $market->save();
if($currency['maintenancemode']) { if ($market->disabled) continue;
$market->price = 0;
$market->save();
continue;
}
$ticker = getCryptsyTicker($market->marketid); $ticker = getCryptsyTicker($market->marketid);
if(!$ticker) continue; if(!$ticker) continue;
@ -481,19 +463,17 @@ function updateCryptsyMarkets()
function updateCCexMarkets() function updateCCexMarkets()
{ {
$exchange = 'c-cex'; $exchange = 'c-cex';
// dborun("update markets set price=0 where name='c-cex'"); <- add that line
$ccex = new CcexAPI; $ccex = new CcexAPI;
$list = $ccex->getPairs(); $list = $ccex->getMarkets();
if (!is_array($list)) return; if (!is_array($list)) return;
foreach($list as $item) foreach($list as $ticker)
{ {
$e = explode('-', $item); if(!isset($ticker['MarketCurrency'])) continue;
if(!isset($e[1])) continue; if(!isset($ticker['BaseCurrency']) || $ticker['BaseCurrency'] != 'BTC') continue;
if($e[1] != 'btc') continue;
$symbol = strtoupper($e[0]); $symbol = strtoupper($ticker['MarketCurrency']);
$coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol'=>$symbol)); $coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol'=>$symbol));
if(!$coin || !$coin->installed) continue; if(!$coin || !$coin->installed) continue;
@ -506,11 +486,16 @@ function updateCCexMarkets()
$market->coinid = $coin->id; $market->coinid = $coin->id;
$market->name = $exchange; $market->name = $exchange;
} }
if ($symbol == 'DCR') $market->disabled = 1;
if ($market->disabled < 9) $market->disabled = !$ticker['IsActive'];
if ($symbol == 'DCR') $market->disabled = 9; // manually disabled
$market->save(); $market->save();
if ($market->disabled) continue;
sleep(1); sleep(1);
$item = strtolower($symbol."-btc");
$ticker = $ccex->getTickerInfo($item); $ticker = $ccex->getTickerInfo($item);
if(!$ticker) continue; if(!$ticker) continue;
@ -658,6 +643,12 @@ function updateYobitMarkets()
$market->name = $exchange; $market->name = $exchange;
} }
$market->txfee = objSafeVal($item,'fee',0.2);
if ($market->disabled < 9) $market->disabled = arraySafeVal($item,'hidden',0);
$market->save();
if ($market->disabled) continue;
$pair = strtolower($coin->symbol).'_btc'; $pair = strtolower($coin->symbol).'_btc';
$ticker = yobit_api_query("ticker/$pair"); $ticker = yobit_api_query("ticker/$pair");
@ -781,13 +772,17 @@ function updateCryptopiaMarkets()
foreach ($data->Data as $ticker) { foreach ($data->Data as $ticker) {
if ($ticker->Label === $pair) { if ($ticker->Label === $pair) {
//$market->marketid = $ticker->TradePairId;
if ($market->disabled < 9) $market->disabled = ($ticker->BidPrice < $ticker->AskPrice/2);
$price2 = ($ticker->BidPrice+$ticker->AskPrice)/2; $price2 = ($ticker->BidPrice+$ticker->AskPrice)/2;
$market->price2 = AverageIncrement($market->price2, $price2); $market->price2 = AverageIncrement($market->price2, $price2);
$market->price = AverageIncrement($market->price, $ticker->BidPrice*0.98); $market->price = AverageIncrement($market->price, $ticker->BidPrice*0.98);
$market->marketid = $ticker->TradePairId; $market->marketid = $ticker->TradePairId;
$market->pricetime = time(); $market->pricetime = time();
$market->save(); $market->save();
if (empty($coin->price)) {
if (empty($coin->price) && !$market->disabled) {
$coin->price = $market->price; $coin->price = $market->price;
$coin->price2 = $market->price2; $coin->price2 = $market->price2;
$coin->save(); $coin->save();
@ -844,13 +839,15 @@ function updateBanxioMarkets()
$pair = strtoupper($coin->symbol).'-BTC'; $pair = strtoupper($coin->symbol).'-BTC';
foreach ($data->result as $ticker) { foreach ($data->result as $ticker) {
if ($ticker->marketname === $pair) { if ($ticker->marketname === $pair) {
$market->price = AverageIncrement($market->price, $ticker->bid);
$market->price2 = AverageIncrement($market->price2, $ticker->last); if ($market->disabled < 9) $market->disabled = (intval($ticker->dayvolume) <= 1);
$market->pricetime = time(); if (!$market->disabled) {
// debuglog("banx: $pair {$ticker->bid} {$ticker->last} => {$market->price} {$market->price2}"); $market->price = AverageIncrement($market->price, $ticker->bid);
if (intval($ticker->dayvolume) > 1) $market->price2 = AverageIncrement($market->price2, $ticker->last);
$market->pricetime = time();
$market->save(); $market->save();
if (empty($coin->price2)) { }
if (empty($coin->price2) && !$market->disabled) {
$coin->price = $market->price; $coin->price = $market->price;
$coin->price2 = $market->price2; $coin->price2 = $market->price2;
$coin->save(); $coin->save();
@ -1025,7 +1022,7 @@ function updateBterMarkets()
$market->price = AverageIncrement($market->price, $ticker['buy']); $market->price = AverageIncrement($market->price, $ticker['buy']);
$market->price2 = AverageIncrement($market->price2, $ticker['avg']); $market->price2 = AverageIncrement($market->price2, $ticker['avg']);
$market->pricetime = time(); $market->pricetime = time();
$market->disabled = (floatval($ticker['vol_btc']) < 0.01); if ($market->disabled < 9) $market->disabled = (floatval($ticker['vol_btc']) < 0.01);
$market->save(); $market->save();
if (empty($coin->price2)) { if (empty($coin->price2)) {

View file

@ -52,9 +52,9 @@ function doBleutradeTrading($quick=false)
debuglog("$exchange: {$coin->symbol} deposit address updated"); debuglog("$exchange: {$coin->symbol} deposit address updated");
$market->deposit_address = $balance->CryptoAddress; $market->deposit_address = $balance->CryptoAddress;
} }
if (property_exists($balance,'IsActive')) { if ($market->disabled < 9 && property_exists($balance,'IsActive')) {
$market->message = ($balance->IsActive == "true") ? "" : "Disabled"; // disabled = 9 means permanent disable by admin
$market->disabled = ($balance->IsActive != "true"); $market->disabled = (int) ($balance->IsActive != "true");
} }
$market->balancetime = time(); $market->balancetime = time();
$market->save(); $market->save();

View file

@ -112,8 +112,8 @@ foreach($list as $market)
echo '<td>'.(empty($traded) ? "" : "$traded ago").'</td>'; echo '<td>'.(empty($traded) ? "" : "$traded ago").'</td>';
echo '<td>'.$late.'</td>'; echo '<td>'.$late.'</td>';
if ($market->disabled) $market->message = trim("{$market->message} (disabled)"); if ($market->disabled) $market->message = trim("{$market->message} disabled");
echo "<td>{$market->message}</td>"; echo '<td align="center">'.$market->message.'</td>';
echo "</tr>"; echo "</tr>";
} }