From 99db377341db890977821a37d28efa6f5596f279 Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sat, 15 Sep 2018 23:52:34 +0200 Subject: [PATCH 1/8] exchange: handle crex24 public api --- web/yaamp/core/backend/markets.php | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/web/yaamp/core/backend/markets.php b/web/yaamp/core/backend/markets.php index da80cd59b..37a42982c 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,57 @@ function updateBleutradeMarkets() ///////////////////////////////////////////////////////////////////////////////////////////// +function updateBitfinexMarkets() +{ + $exchange = 'bitfinex'; + if (exchange_get($exchange, 'disabled')) return; + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + + foreach($list as $market) + { + $coin = getdbo('db_coins', $market->coinid); + if(!$coin) continue; + $symbol = $coin->getOfficialSymbol(); + $pair = strtolower($symbol).'btc'; + + $ticker = bitfinex_api_query('pubticker', $pair); + + $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}"); + // Limit to 10 API call so 10 tickets ? https://docs.bitfinex.com/docs/rest-general + } +} + + ///////////////////////////////////////////////////////////////////////////////////////////// + function updateBitzMarkets($force = false) { $exchange = 'bitz'; From 30b5ab7c06bb1c6400a3430726548766a828a88d Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sat, 15 Sep 2018 23:55:27 +0200 Subject: [PATCH 2/8] exchange: handle bitfinex public api --- web/yaamp/core/backend/rawcoins.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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; } From 2b49cba5c1e4f530a9700410f08b527b2e2a55d7 Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sat, 15 Sep 2018 23:56:04 +0200 Subject: [PATCH 3/8] Create bitfinex.php --- web/yaamp/core/exchange/bitfinex.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 web/yaamp/core/exchange/bitfinex.php diff --git a/web/yaamp/core/exchange/bitfinex.php b/web/yaamp/core/exchange/bitfinex.php new file mode 100644 index 000000000..bea2e432b --- /dev/null +++ b/web/yaamp/core/exchange/bitfinex.php @@ -0,0 +1,21 @@ + Date: Sat, 15 Sep 2018 23:57:08 +0200 Subject: [PATCH 4/8] Update exchange.php --- web/yaamp/core/exchange/exchange.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/web/yaamp/core/exchange/exchange.php b/web/yaamp/core/exchange/exchange.php index 53ce0e492..ae5a9c406 100644 --- a/web/yaamp/core/exchange/exchange.php +++ b/web/yaamp/core/exchange/exchange.php @@ -13,6 +13,7 @@ function strip_data($data) return $out; } +require_once("bitfinex.php"); require_once("bitstamp.php"); require_once("bittrex.php"); require_once("bitz.php"); @@ -82,6 +83,8 @@ function getMarketUrl($coin, $marketName) $url = "https://alcurex.com/#{$symbol}-{$base}"; else if($market == 'binance') $url = "https://www.binance.com/trade.html?symbol={$symbol}_{$base}"; + else if($market == 'bitfinex') + $url = "https://www.bitfinex.com/t/{$symbol}:{$base}"; else if($market == 'bittrex') $url = "https://bittrex.com/Market/Index?MarketName={$base}-{$symbol}"; else if($market == 'bitz') From d36e5c6affa57174c67a9f64b84602317c55766a Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sun, 16 Sep 2018 00:19:14 +0200 Subject: [PATCH 5/8] Update markets.php --- web/yaamp/core/backend/markets.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/web/yaamp/core/backend/markets.php b/web/yaamp/core/backend/markets.php index 37a42982c..33bdc4837 100644 --- a/web/yaamp/core/backend/markets.php +++ b/web/yaamp/core/backend/markets.php @@ -300,15 +300,20 @@ function updateBitfinexMarkets() $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); @@ -338,7 +343,6 @@ function updateBitfinexMarkets() $coin->save(); } //debuglog("$exchange: $pair price updated to {$market->price}"); - // Limit to 10 API call so 10 tickets ? https://docs.bitfinex.com/docs/rest-general } } From 391c7744f4049938b695d5e716e1ebbd67a2a36f Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sun, 16 Sep 2018 00:20:34 +0200 Subject: [PATCH 6/8] Update markets.php --- web/yaamp/core/backend/markets.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/yaamp/core/backend/markets.php b/web/yaamp/core/backend/markets.php index 33bdc4837..437bc1c8e 100644 --- a/web/yaamp/core/backend/markets.php +++ b/web/yaamp/core/backend/markets.php @@ -311,8 +311,8 @@ function updateBitfinexMarkets() $ticker = bitfinex_api_query('pubticker', $pair); - $count++; - if ($count > 10) {sleep(10);$count=0;} // Rate limiting https://docs.bitfinex.com/docs/rest-general + $count++; + if ($count > 10) {sleep(10);$count=0;} // Rate limiting https://docs.bitfinex.com/docs/rest-general $sqlFilter = ''; if (!empty($market->base_coin)) { From 4574ad179e2636312c9026e4c3d5ba6c13d4aef7 Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Sun, 16 Sep 2018 00:22:01 +0200 Subject: [PATCH 7/8] Update bitfinex.php --- web/yaamp/core/exchange/bitfinex.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web/yaamp/core/exchange/bitfinex.php b/web/yaamp/core/exchange/bitfinex.php index bea2e432b..2080425c0 100644 --- a/web/yaamp/core/exchange/bitfinex.php +++ b/web/yaamp/core/exchange/bitfinex.php @@ -1,5 +1,7 @@ Date: Sun, 16 Sep 2018 13:24:12 +0200 Subject: [PATCH 8/8] Update bitfinex.php --- web/yaamp/core/exchange/bitfinex.php | 1 + 1 file changed, 1 insertion(+) diff --git a/web/yaamp/core/exchange/bitfinex.php b/web/yaamp/core/exchange/bitfinex.php index 2080425c0..474c5b42e 100644 --- a/web/yaamp/core/exchange/bitfinex.php +++ b/web/yaamp/core/exchange/bitfinex.php @@ -3,6 +3,7 @@ // https://docs.bitfinex.com/docs/rest-general // https://docs.bitfinex.com/v1/reference#rest-public-ticker // https://api.bitfinex.com/v1/symbols +// not used yet : https://api.bitfinex.com/v1/symbols_details // https://api.bitfinex.com/v1/pubticker/btcusd function bitfinex_api_query($method, $params='', $returnType='object')