diff --git a/web/yaamp/core/backend/markets.php b/web/yaamp/core/backend/markets.php index da80cd59b..437bc1c8e 100644 --- a/web/yaamp/core/backend/markets.php +++ b/web/yaamp/core/backend/markets.php @@ -10,6 +10,7 @@ function BackendPricesUpdate() settings_prefetch_all(); + updateBitfinexMarkets(); updateBittrexMarkets(); updateBitzMarkets(); updatePoloniexMarkets(); @@ -292,6 +293,61 @@ function updateBleutradeMarkets() ///////////////////////////////////////////////////////////////////////////////////////////// +function updateBitfinexMarkets() +{ + $exchange = 'bitfinex'; + if (exchange_get($exchange, 'disabled')) return; + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + + $count=0; + foreach($list as $market) + { + $coin = getdbo('db_coins', $market->coinid); + if(!$coin) continue; + if (!($coin->installed || $coin->watch)) continue; + $symbol = $coin->getOfficialSymbol(); + $pair = strtolower($symbol).'btc'; + + $ticker = bitfinex_api_query('pubticker', $pair); + + $count++; + if ($count > 10) {sleep(10);$count=0;} // Rate limiting https://docs.bitfinex.com/docs/rest-general + + $sqlFilter = ''; + if (!empty($market->base_coin)) { + $pair = strtolower($symbol.$market->base_coin); + $sqlFilter = "AND base_coin='{$market->base_coin}'"; + } + if (market_get($exchange, $symbol, "disabled")) { + $market->disabled = 1; + $market->message = 'disabled from settings'; + $market->save(); + continue; + } + +// if ($market->disabled < 9) { +// $nbm = (int) dboscalar("SELECT COUNT(id) FROM markets WHERE coinid={$coin->id} $sqlFilter"); +// $market->disabled = ($ticker->bid < $ticker->ask/2) && ($nbm > 1); +// } + + $price2 = ($ticker->bid+$ticker->ask)/2; + $market->price2 = AverageIncrement($market->price2, $price2); + $market->price = AverageIncrement($market->price, $ticker->bid); + $market->pricetime = time(); // $ticker->timestamp "2018-08-31T12:48:56Z" + $market->save(); + + if (empty($coin->price) && $ticker->ask) { + $coin->price = $market->price; + $coin->price2 = $price2; + $coin->save(); + } + //debuglog("$exchange: $pair price updated to {$market->price}"); + } +} + + ///////////////////////////////////////////////////////////////////////////////////////////// + function updateBitzMarkets($force = false) { $exchange = 'bitz'; diff --git a/web/yaamp/core/backend/rawcoins.php b/web/yaamp/core/backend/rawcoins.php index 2515a4063..dbcced685 100644 --- a/web/yaamp/core/backend/rawcoins.php +++ b/web/yaamp/core/backend/rawcoins.php @@ -36,6 +36,18 @@ function updateRawcoins() } } + if (!exchange_get('bitfinex', 'disabled')) { + $list = bitfinex_api_query('symbols'); + if(is_array($list) && !empty($list)) { + dborun("UPDATE markets SET deleted=true WHERE name='bitfinex'"); + foreach ($list as $pair) { + if (strpos($pair, 'usd') || !strpos($pair, 'btc')) continue; + $symbol = strtoupper(str_replace('btc', '', $pair)); + updateRawCoin('bitfinex', $symbol); + } + } + } + if (!exchange_get('bitz', 'disabled')) { $list = bitz_api_query('tickerall'); if (!empty($list)) { @@ -444,7 +456,7 @@ function updateRawCoin($marketname, $symbol, $name='unknown') } } - if (in_array($marketname, array('nova','askcoin','binance','bitz','coinexchange','coinsmarkets','cryptobridge','hitbtc'))) { + if (in_array($marketname, array('nova','askcoin','binance','bitfinex','bitz','coinexchange','coinsmarkets','cryptobridge','hitbtc'))) { // don't polute too much the db with new coins, its better from exchanges with labels return; } diff --git a/web/yaamp/core/exchange/bitfinex.php b/web/yaamp/core/exchange/bitfinex.php new file mode 100644 index 000000000..474c5b42e --- /dev/null +++ b/web/yaamp/core/exchange/bitfinex.php @@ -0,0 +1,24 @@ +